Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Wild card in regular expression

by toolic (Chancellor)
on Nov 28, 2012 at 21:14 UTC ( #1006103=note: print w/ replies, xml ) Need Help??


in reply to Wild card in regular expression

Tip #9 from the Basic debugging checklist : YAPE::Regex::Explain

The regular expression: (?-imsx:(ther*)) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- the 'the' ---------------------------------------------------------------------- r* 'r' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------

Use . instead. Also, with different delimiters, you can clean up the replacement string:

use warnings; use strict; my $test = "Here is the there"; $test =~ s{(ther.)}{<test>$1</test>}ig; print "$test\n"; __END__ Here is the <test>there</test>


Comment on Re: Wild card in regular expression
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2014-11-25 02:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (148 votes), past polls