Complex Regular Expression: JavaScript

Author Message
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)
0
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
 
#1
    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)
    0
    Problem solved:

    /^\/((?![*\/])(?:\\\/|[^\n\r\u2028\u2029\/])+[^\n\r\u2028\u2029\\])\/([gimy]*)/
    To iterate is human, to recurse divine. -- L. Peter Deutsch
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9