Results 1 to 6 of 6

Thread: More RegEx help, (looking back?)

  1. #1

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Resolved More RegEx help, (looking back?)

    yesterday DeadEyes thought be about ?= that is a look ahead assertion. But is there something for looking back too? I need to find a function definition. And it always has "def" infront of it. and a ( after it. So to find a function I can do:
    \b[\w\d_]*(?=\()


    but I need to add to that to match it ONLY if "def" is in front of it.

    I.e:
    def _ma5in_(


    Anyone have any ideas.


    ØØ
    Last edited by NoteMe; Jun 26th, 2005 at 04:24 AM.

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196

    Re: More RegEx help, (looking back?)

    yes there is
    (?=) lookahead
    (?<=) lookbehind
    these are for positive matches there are also negative ones;some good info can be found here http://www.regular-expressions.info/

  3. #3

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: More RegEx help, (looking back?)

    wohhooo...will test it and see if I can make it work right away.

  4. #4

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: More RegEx help, (looking back?)

    Great page. Took me a while to understand that the look behind had to be in front of the expression I had to match.....but the syntax I have come up with now is like this..

    (?<=def\s)[\w\d_]*



    and it seems like it works. This is so fun..


    Thanks a million.
    ØØ

  5. #5

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: More RegEx help, (looking back?)

    Well it worked in my RegEx coatch testing tool. But JS is not eating it......

  6. #6

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: More RegEx help, (looking back?)

    Hehe...I am pretty stupid though....JS doesn't support lookbehind at all....thats why it isn't working...


    So it is possible to use the ^ for a whole word in staed of just ONE letter? Because if I do this:

    [^def] then it will just test for d or e or f. Not the word def. I have too rule out all matches that has the def word in front.


    so it will trigger on this one:

    if sef():

    but not this one at all:

    def _ma5in_():
    Last edited by NoteMe; Jun 25th, 2005 at 10:31 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width