Correct regular expression for backslash

I am trying to write a script to search for backslashes in a URL string, but my script doesn't seem to be working.  I'm hoping someone can help me figure this out.  Right now, I just want to be alerted when there is a backslash in a string.  Once I know this is working, then I'll work on the true functionality of the method itself.  Here is the function I have right now:

string doubleSlashes(string s) {
    Buffer str = create;
    str = s;
    Regexp slash = regexp2("/\\/g");
    
    if (search(slash, str, 0)) {
        infoBox("There is at least one backslash.")
    }
    return s;
}

If somebody could please help me get this regular expression correct, it would be very much appreciated.

 

Chris


chrscote - Wed Mar 29 12:43:35 EDT 2017

Re: Correct regular expression for backslash
Mathias Mamsch - Wed Mar 29 15:49:41 EDT 2017

Well the regexp to match a backslash is \\ and if you make a DXL string of it:

"\\\\"

DOORS does not have the linux style regexps where you put a delimiter at the start and the end and can put some flags like g (global) in there.

Regards, Mathias

Re: Correct regular expression for backslash
chrscote - Thu Mar 30 08:05:12 EDT 2017

OK, thanks again Mathias.  Am I correct in counting 4 slashes for a single backslash in the DXL string?  If I need to change each backslash to a double backslash, would I use 8 slashes or 6?

 

Within the if statement, I want to loop through the string and double any single backslash

Here's what I want to do:

string doubleSlashes(string s) {
    Buffer str = create;
    str = s;
    int len = length s;
    int i=0, j=0;
    
    for (j=0; j<len; j++){
        if (s[j]=="\\\\") {
            //add another slash at this point in the string
        }
    }
}

 

Chris