Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Think about Loose Coupling
 
PerlMonks  

Re: Mind boggling regex

by japhy (Canon)
on Oct 26, 2001 at 18:01 UTC ( #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:??;


Comment on Re: Mind boggling regex
Download Code
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
Node Status?
node history
Node Type: note [id://121629]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2014-04-19 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (480 votes), past polls