TNO
-
Total Posts
:
2094
- Scores: 36
-
Reward points
:
0
- Joined: 12/18/2004
- Location: Earth
-
Status: offline
|
Complex Regular Expression: JavaScript
Friday, January 16, 2009 2:36 AM
( permalink)
I've been trying to figure out how to write a regular expression to match a regular expression literal, but am having issues with false positives. Here's what I have currently: /^(?:\/((?:\\.|\[(?:\\.|[^\]])*\]|[^\/])+)\/([gimy]*))/i and here is an example of a string it gives a false positive on: / 2; //comment var b = /\n/g; Any thoughts on what I may be doing wrong with this regular expression? (FYI: THis code is part of a tokenizer so the leading portions of the input string are removed as matches are found, which is why the division operator is now the first character in the input string). As always, any insight is appreciated
<message edited by TNO on Friday, January 16, 2009 2:37 AM>
To iterate is human, to recurse divine. -- L. Peter Deutsch
|
|
|
|
TNO
-
Total Posts
:
2094
- Scores: 36
-
Reward points
:
0
- Joined: 12/18/2004
- Location: Earth
-
Status: offline
|
RE: Complex Regular Expression: JavaScript
Friday, January 16, 2009 9:32 AM
( permalink)
Problem solved: /^\/((?![*\/])(?:\\\/|[^\n\r\u2028\u2029\/])+[^\n\r\u2028\u2029\\])\/([gimy]*)/
To iterate is human, to recurse divine. -- L. Peter Deutsch
|
|
|
|