in reply to Re: Regular expression help: why does this not match?
in thread Regular expression help: why does this not match?

yes, i figured that... so if i have a very long string that contains multiple possible regex metacharacters, how can i do a match and tell that match to "ignore" any such metacharacters? or do i have to process the string first and backslash all of them??
  • Comment on Re^2: Regular expression help: why does this not match?

Replies are listed 'Best First'.
Re^3: Regular expression help: why does this not match?
by ikegami (Patriarch) on Jan 18, 2007 at 23:49 UTC

    Or don't use a regexp at all.

    $a =~ /^\Q$b\E\z/
    is equivalent to
    $a eq $b

    $a =~ /\Q$b\E/
    is equivalent to
    index($a, $b) >= 0

    Case-insensitive versions:

    $a =~ /^\Q$b\E\z/i
    is equivalent to
    lc($a) eq lc($b)

    $a =~ /\Q$b\E/i
    is equivalent to
    index(lc($a), lc($b)) >= 0

Re^3: Regular expression help: why does this not match?
by Zaxo (Archbishop) on Jan 18, 2007 at 23:06 UTC

    quotemeta or \Q as I added to my original reply.

    After Compline,
    Zaxo