Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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 imbibing at the Monastery: (16)
As of 2015-07-28 21:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (259 votes), past polls