Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2016-12-04 17:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (69 votes). Check out past polls.