Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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?
[marto]: in house as in Company network, not internet connected (power stations and the corporate HQs)
[Discipulus]: new Monsignor party! free beverages and pizza for all you monks! and a big thanks for the patience you deserved me during these years
[marto]: congrats Discipulus
[Discipulus]: only 4k points to sundial's level ..;=)
[Corion]: Yay Discipulus ;)
[Corion]: marto: Ah, so this will be training videos etc., cool!
[choroba]: Congratulations!
[marto]: Corion worse, some plant inspection, cameras moving thru pipes
[marto]: Discipulus yeah, just don't adopt his tactics :P
[marto]: the content for the most part is fairly dull, but if they go for it, they can use it for all sorts of video, they have no solution for this at the moment

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2017-07-28 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (425 votes). Check out past polls.