Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Match the starting \>

by almut (Canon)
on May 15, 2009 at 05:45 UTC ( [id://764186]=note: print w/replies, xml ) Need Help??


in reply to Match the starting \>

Not entirely sure I understand, but maybe you want a character class [...], i.e.

for ("< foo\n", "> bar\n") { my $lines = $_; if($lines =~ m/[<>]/){ $lines =~ s/^[<>]\s//; # do something else... } print $lines; } __END__ foo bar

Update: as grizzley suggested, you could also use /<|>/ (alternation). While that would even be one char less to type in your match, it would become slightly more unwieldy in case the regex needs to contain other stuff, like in the substitution:

$lines =~ s/^(?:<|>)\s//;

(the (?:...) groups without capturing)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-25 14:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found