in reply to regex patterns

$pattern = shift; $file = shift; open(MAT, "<$file") or die "bad file name"; $text = <MAT>; while($text =~ /\Q$pattern\E/g) { $x += 1; } print "found $x matches\n"; close(MAT);
The \Q and \E are regex "quotes". That means characters with special meaning lose those meanings and become literal. If you want the user to be able to use regex special characters, just remove the \Q & \E.

Replies are listed 'Best First'.
Re: Re: regex patterns
by dogbert (Scribe) on Jan 31, 2003 at 02:45 UTC
    Thanks ----------------------------------------------------------- Height : varies depending on my speed relative to the observer Weight : is a sensation caused by the gravitational wrapping of time-space Age : time is only a persistent illusion
      Your welcome. A few well placed <p>'s in your signature would be nice ;)