in reply to Regexp help!!

I have commented a regex that works with the data that you have provided. The two values that you are looking for are placed in $2 and $3.
use strict; use warnings; my $a=' $text=~s#Find \#Text#Replace Text#; $text=~s/Find \/Text/Replace Text/; $text=~s{Find \}Text}{Replace Text}; '; if ($a =~ / # start \$text=~s # remember to escape the $ to avoid interpolation (.) # capture the '#' (.*?) # match any non-newline character non-greedily (?<!\\) # make sure the '#' is not escaped in your data \1 # the first unescaped '#' (.*?) # match any non-newline character non-greedily \1; # the second '#' /x # end ) { # need value $findtext='Find \#Text'; print "$2\n"; # need value $repltext='Replace Text'; print "$3\n" }

Replies are listed 'Best First'.
Re^2: Regexp help!!
by Roy Johnson (Monsignor) on Oct 21, 2005 at 14:02 UTC
    You might have a problem with an escaped backslash before the 2nd #. Your (.*?) should probably be
    ((?:\\?.)*?) # match possibly-backslashed non-newline, non-greedy

    Caution: Contents may have been coded under pressure.