Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Mind boggling regex

by japhy (Canon)
on Oct 26, 2001 at 18:01 UTC ( [id://121629]=note: print w/replies, xml ) Need Help??


in reply to Mind boggling regex

Character classes are formed at regex compile-time, and \1 isn't a backreference until regex run-time, so your character class is saying "all characters except the character with octal code 001". Try something like:
$word =~ /(e)(?!\1)(.)e/s;
which reads "match an e, then, making sure we CAN'T match an e, match ANY character, then match an e." The /s is there so that . matches newline.

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: Mind boggling regex
by Anonymous Monk on Oct 26, 2001 at 21:40 UTC
    $word =~ /(e)(?!\1)(.)e/s;
    I just tried that regex, and $1, $2, and $3 are all undefined.

    Does the look-ahead somehow make all the saved regex matches disappear or something?

    Magius_AR

      Well, the regex FAILS for the string "eee". Try "eye" instead. And this regex only defines $1 and $2.

      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://121629]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-23 19:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found