Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Problems with matching and metacharacters

by WebHick (Scribe)
on Jun 14, 2001 at 19:00 UTC ( [id://88444]=note: print w/replies, xml ) Need Help??

in reply to Problems with matching and metacharacters

Simply put \Q and \E around $input. Like so:

Don't do this:
Because the regex will also try to match the parenthesis.

Update: I never said I was fast.

Replies are listed 'Best First'.
Re: Re: Problems with matching and metacharacters
by Anonymous Monk on Jun 14, 2001 at 19:55 UTC
    Actually, the \E is not needed, since $input is the only thing in the regex; that is, it is automatically ended.
    Here's a question: Why would you need to put parentheses around $input? You can access its value more efficiently as $input, than as $1, since parentheses would slow down the regex. More succintly, change the code to this:
    And change occurences of $1 to $input

      Actually, /(\Q$input)/ produces the error:

      /(\(\)/: unmatched () in regexp

      because you're now matching $input), not just $input. If the parenthesis are to stay, you'll need the \E


Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-05-24 18:47 GMT
Find Nodes?
    Voting Booth?

    No recent polls found