RE: Slashing back at RegExp

Date : Tue, 25 Oct 2005 13:44:30 -0400
To : <XSI(at)Softimage.COM>
From : "Stephen Blair" <stephen_blair(at)Softimage.COM>
Subject : RE: Slashing back at RegExp
When you create a RegExp object, you have to deal with two levels of escaping. First, escaping the backslash in the .js file, and then escaping the backslash in the RegExp constructor.

When you type a backslash in a .js file, you have to type "\\".
So when you write RegExp( "\\" ), you are giving RegExp a single backslash. That single backslash has to escape something.

For example:


s = "\\\\server";
LogMessage( s );

re2 = new RegExp( '\\\\' );
LogMessage( s.match( re2 ) );	//INFO : \


re = new RegExp( '\\\\\\\\' );
LogMessage( s.match( re ) );	//INFO : \\

re1 = /\\/;
LogMessage( s.match( re1 ) );	//INFO : \




-----Original Message-----
From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM]On Behalf
Of brad
Sent: Tuesday, October 25, 2005 1:08 PM
To: xsi(at)Softimage.COM
Subject: Slashing back at RegExp


In jscript, the following raises an error:

    re = new RegExp("\\");

And so does this:

    var str = "C:\\";
    re = new RegExp(str);


I have a workaround that gets the job done, but I was wondering if anyone has figured out a way to instantiate the RegExp object for backslashes.


Cheers!
-Brad
---
Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
unsubscribe xsi

---
Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
unsubscribe xsi


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.