[flexcoders] Re: Replacing double slash with a single slash
Can you give an example source string and how you would want it to look? Or a couple so that I don't just look at a single instance? --- In flexcoders@yahoogroups.com, Nick Middleweek wrote: > > Hi Valdor, > > Thanks for the reply, I've just tried this code but no joy... :( > > var doubleSlash : RegExp = //g; > var slash : RegExp = //; > winMessage = winMessage.replace( doubleSlash, slash ); > > I'm sure it's easy when you know how :) > > > Nick > > > > On 8 November 2011 19:24, valdhor wrote: > > > ** > > > > > > As I understand it the backslash character is special in both the regex > > and the replacement string, so it has to be double escaped in both places. > > That means, for every single backslash you want to match or insert, you > > have to put *four* backslashes in the regex or replacement string. > > > > > > --- In flexcoders@yahoogroups.com, Nick Middleweek wrote: > > > > > > Hi, > > > > > > I'm trying to replace a double slash with a single slash and am having a > > > little trouble, has anyone done this before? > > > > > > Here's what I've got thus far... > > > > > > var doubleSlash : RegExp = /(\\)(\\)/g; > > > var slash : RegExp = /(\\)/; > > > > > > winMessage = winMessage.replace( doubleSlash, slash ); > > > > > > > > > Cheers, > > > Nick > > > > > > > > > >
Re: [flexcoders] Re: Replacing double slash with a single slash
Hi Valdor, Thanks for the reply, I've just tried this code but no joy... :( var doubleSlash : RegExp = //g; var slash : RegExp = //; winMessage = winMessage.replace( doubleSlash, slash ); I'm sure it's easy when you know how :) Nick On 8 November 2011 19:24, valdhor wrote: > ** > > > As I understand it the backslash character is special in both the regex > and the replacement string, so it has to be double escaped in both places. > That means, for every single backslash you want to match or insert, you > have to put *four* backslashes in the regex or replacement string. > > > --- In flexcoders@yahoogroups.com, Nick Middleweek wrote: > > > > Hi, > > > > I'm trying to replace a double slash with a single slash and am having a > > little trouble, has anyone done this before? > > > > Here's what I've got thus far... > > > > var doubleSlash : RegExp = /(\\)(\\)/g; > > var slash : RegExp = /(\\)/; > > > > winMessage = winMessage.replace( doubleSlash, slash ); > > > > > > Cheers, > > Nick > > > > >
[flexcoders] Re: Replacing double slash with a single slash
As I understand it the backslash character is special in both the regex and the replacement string, so it has to be double escaped in both places. That means, for every single backslash you want to match or insert, you have to put *four* backslashes in the regex or replacement string. --- In flexcoders@yahoogroups.com, Nick Middleweek wrote: > > Hi, > > I'm trying to replace a double slash with a single slash and am having a > little trouble, has anyone done this before? > > Here's what I've got thus far... > > var doubleSlash : RegExp = /(\\)(\\)/g; > var slash : RegExp = /(\\)/; > > winMessage = winMessage.replace( doubleSlash, slash ); > > > Cheers, > Nick >