Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Regexp help!!

by inman (Curate)
on Oct 21, 2005 at 11:30 UTC ( [id://501961]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://501961]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-24 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found