Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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
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
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 musing on the Monastery: (6)
As of 2015-07-28 05:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls