in reply to regexp question

Untested, but should get the idea across.

my $path =~ /^\Q$str\E # the base string; '\tmp\foo', e.g. (\\.*)? # optionally match a slash, etc. $ # match end of string /x;

Insisting on matching $ at the end of the regex prevents you from matching "extra" chars that don't start with a backslash.

Update: Yes, do escape the base string. (Regex updated.) Thanks Sweeper!

--
:wq

Replies are listed 'Best First'.
Re x 2: regexp question
by Sweeper (Pilgrim) on Feb 12, 2002 at 06:20 UTC
    I have not tested either, but I think you should escape special characters in $string:
    my $path =~ /^\Q$string\E  # the base string; '\tmp\foo', e.g.
                   (\\.*)?     # optionally match a slash, etc.
                   $           # match end of string
                  /x;