Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re: A Regex to identify Regex's / Compiling a regex

by knowmad (Monk)
on Sep 19, 2002 at 22:01 UTC ( #199318=note: print w/replies, xml ) Need Help??


in reply to Re: A Regex to identify Regex's / Compiling a regex
in thread A Regex to identify Regex's / Compiling a regex

Ahhh, now I see! Thanks for editing that regex for me. I like your explanation of why using a \\ at the end fails. However, if the regex did not match, then a compile error would not occur as it would not enter the if statement.

Following your suggestion of using the m!! format works. So the problem lies in how the regex is getting compiled. I did a bit more testing and discovered that using the \\ fails when it is next to a \/ combination (on either side). It fails if I use the // or m// style. At this point it's mostly a matter of curiousity but an interesting anomaly within either the eval function or the Perl regex engine.

Thanks, William

  • Comment on Re: Re: A Regex to identify Regex's / Compiling a regex

Replies are listed 'Best First'.
Re: Re: Re: A Regex to identify Regex's / Compiling a regex
by bart (Canon) on Sep 19, 2002 at 22:41 UTC
    At this point it's mostly a matter of curiousity but an interesting anomaly within either the eval function or the Perl regex engine.
    It's not. It's just that you're trying to match a backslash, for which you need a double backslash in the regex. But to achieve that, you need to type 4 backslashes in a singlequotish string. It's what's in the string that matters for the regex engine, not what's in your source code.

    A backslash only disappears in such a string, if it's in front of a backlslash or a string delimiter (here "'").

Re: Re: Re: A Regex to identify Regex's / Compiling a regex
by BrowserUk (Pope) on Sep 19, 2002 at 22:47 UTC

    I don't think there is any mystery here. Although the regexes are originally within single quotes and therefor not interpolated, in the eval they are being concatenated with the rest of the sub statement. The eval see's it just as a string. When the interpreter tries to evaluate the combined string the final delimiter of the match is escaped, hence the error, Search pattern not terminated.

    It get's into the if statement ok, but its when its concatenated prior to evaluation where the problem arises.

    That's why using m!! cures the problem.

    I'll add... I think, cos I'm not great with regexes.


    Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://199318]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2017-12-12 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (320 votes). Check out past polls.

    Notices?