Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Regex Problem

by ido50 (Scribe)
on Aug 25, 2003 at 09:42 UTC ( [id://286336]=perlquestion: print w/replies, xml ) Need Help??

ido50 has asked for the wisdom of the Perl Monks concerning the following question:

Hi!
One of my programs uses a simple regex to match a string in a text file. The string is inside an html tag so the regex is something like m/^<[^>]+>$string<\/[^>]+>$/. Anyway the regex always works unless the string contains some parentheses. For example: "Hi there" would match, "Hi there (Mark)" wouldn't.
What can I do?
P.S. Might be worth mentioning the strings are all hebrew.

Thanks...

-------------------------
Live fat, die young

Replies are listed 'Best First'.
Re: Regex Problem
by liz (Monsignor) on Aug 25, 2003 at 10:00 UTC
Re: Regex Problem
by CombatSquirrel (Hermit) on Aug 25, 2003 at 10:26 UTC
    Adding to liz' (completely correct) comment: The parens are RegEx metacharachters used for grouping and capturing. For example, $string = 'Hi there (Mark)'; m/^<[^>]+>$string<\/[^>]+>$/; would be exactly the same as m/^<[^>]+>Hi there (Mark)<\/[^>]+>$/;, which matches "Hi there Mark" between tags and captures the "Mark" part of it. quotemeta(...) and its RegEx equivalent m/\Q...\E/ (quote ... end) escape all the RegEx metacharachters properly (i.e. (Mark) to \(Mark\)).
    And that's about it.
    Hope this helped.
    CombatSquirrel.
Re: Regex Problem
by ido50 (Scribe) on Aug 25, 2003 at 10:46 UTC
    thanks guys..

    -------------------------
    Live fat, die young

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-26 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found