KW.pm | Regular Expressions | #13 |
if( $input =~ /\bx(\d{4})\b/ ) { # Can we match a phone extension? $phone_ext = $1; }Or even within the same match:
/(.*) \1/ # Matches anything occurring twice with a space inbetween # like "aniMAL MALaise" or "It was THAT THAT did it in."Or substitution:
s/\b(\w+) (\w+)\b/$2 $1/ # Reverses two words
"An example:" =~ /^\w+( (.{4}).*)$/; # Sets $1 to the inner "exam" # and $2 to the outer " example:"
/(\w+) \1/ # Matches double words like "To see that that succeeds"
<< Previous | Index | Next >> | Copyright © 2002 Christopher Calzonetti |