An interesting little question, can the following regular expression replace success?
var __str:string = \' 12346789\ '; Trace (__str.replace (/\ \/g, \' 5\ ' ));
The answer is: no . The result of the trace is:
[Trace] 12346789
In fact, the regular itself is not written wrong, wrong in the string being replaced. The backslash "" is an escape character in AS3, and any subsequent value will be converted to itself, so the string you see actually is, that is 12346789
, no backslash, of course, cannot be searched.
Directly trace(__str)
, the result is the same as the trace above.
To get the correct result, you need to set the string to: 1234\\6789
we see two backslashes, and AS3 thinks it's a backslash.
If you are using regexp to establish a regular, you need to use 4 backslashes:
var __str:string = \' 1234\\6789\ '; var New REGEXP (\' \\\\\ ', \' \ '); Trace (__str.replace (__reg, \' 5\ '));
This happens only when a hard-coded string is present, and if the string appears in TextField, the string taken from Textfield.text is automatically escaped, and a backslash is actually two backslashes.
Transferred from: http://zengrong.net/post/1374.htm
AS3 the substitution of a backslash in a regular expression