Created
May 6, 2013 05:39
-
-
Save debreuil/5523531 to your computer and use it in GitHub Desktop.
Oh Javascript...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
| <html> | |
| <script> | |
| // need to manually set re.lastIndex = 0; or this happens | |
| var s1 = "bc11bc22f"; | |
| var s2 = "bc33bc44g"; | |
| var re = /.*?(bc..)/g; | |
| var result1 = re.exec(s1);//bc11 | |
| var result2 = re.exec(s2);//bc44 | |
| alert(result1 + " --- " + result2); | |
| // .............. | |
| var result = ""; | |
| var s1 = "bc11bc22bc33"; | |
| var comma = ""; | |
| for(var i = 0; i < 3; i++) | |
| { | |
| var re = /.*?(bc..)/g; | |
| var ar = re.exec(s1); | |
| result += comma + ar[1]; | |
| comma = ","; | |
| } | |
| alert(result); // bc11,bc11,bc11 in browser | |
| //trace(result);// bc11,bc22,bc33 in jsfl | |
| </script> | |
| <body class="TPtext"> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment