Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Common Regex Gotchas

by chromatic (Archbishop)
on Apr 26, 2000 at 00:00 UTC ( #9096=perltutorial: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my $data = "<tag>this is a line of code</tag>
    <explanation>this is where I wax poetic about my code</explanation>
    <tag>this is another example of code</tag>";
    if ($data =~ /<tag>(.*)<\/tag>/s) {
        print "I found =>$1<=\n";
    }
    
  2. or download this
    I found =>this is a line of code</tag>
    <explanation>this is where I wax poetic about my code</explanation>
    <tag>this is another example of code<=
    
  3. or download this
     if ($data =~ /<tag>(.*?)<\/tag>/s) {
        print "I found =>$1<=\n";
    }
    
  4. or download this
    my $line = "Name: Some Soldier, Rank:  Leftenant, Serial: 426879824, Boots:  black";
  5. or download this
    $line =~ /^\w*: \w*\s*\w*, \w*: \w*, \w+: (\d)*, \w*: \w*$/;
  6. or download this
    $line =~ /[Ss]erial: (\d{9})/;
  7. or download this
    $line =~ /<title>(.*?)</title>/;
  8. or download this
    $line =~ m!<title>(.*?)</title>!;
  9. or download this
    my $line = "a.b.cd*f.";
    $line =~ /([^.*]{2})/;
    
  10. or download this
    my $input = "foo bar baz";
    $input =~ s/(\w+)/uc($1)/ge;
    
  11. or download this
    $intput =~ s/([A-Za-z]+)/uc($1)/ge;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-09-01 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (15 votes), past polls