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