Regular Expressions are often used, but they are basically used to verify the rationality of a string. For example:
VaR M = "12345 ";
VaR n =/^/d + $ /;
If (N. Test (M) Alert ('OK ');
Today I have read an example about using regular expressions in the replace method, which is very valuable and can be easily implemented, such as the lenb and trim methods.
I Want To sum up not this, but replace the pattern with $ in replace, for example:
VaR M = eval ("/(northsnow) +/g ");
VaR n = "I am northsnow, I come from Jilin ";
VaR t = n. Replace (M, "<B> $1 </B> ");
Alert (N );
The result is as follows: I am <B> northsnow </B>, I come from Jilin ";
The matching results in the brackets are extracted and put into the $ variable. $1 stores the matching of the first pattern, $2 stores the matching of the second pattern, and so on.
For example:
VaR M = "northsnow is a good man ";
VaR n = M. Replace (/s) ([A-Z] +)/g, "$1 ")
Result: northsnow
VaR n = M. Replace (/s) ([A-Z] +)/g, "$2 ")
Result: northsnowisagoodman
In addition, there is a/num that can be used. The num here is an integer, which indicates that the num-th mode is put here.
If (.)/1, it indicates two consecutive repeated characters.
If (.)/D */1 represents two identical characters with N numbers in the middle, N> = 0
Here is an example. As long as you have mastered the skills, you can accumulate experience through practice.