Next | Regular Expression Mastery | 45 |
To make . match anything at all, even \n, use the /s modifier.
$time = <STDIN>; # "11:29\n" ($minutes) = ($time =~ /:(.*)$/s);
$minutes is now "29\n" rather than "29"
This might be useful in HTML matching, for example:
<p align=center><table align=center border=1><font size="+2"> <tr><td>\d</td><td>[0-9]</td></tr> <tr><td>\D</td><td>[^0-9]</td></tr> <tr><td>\w</td><td>[A-Za-z0-9_]</td></tr> <tr><td>\W</td><td>[^A-Za-z0-9_]</td></tr> <tr><td>\s</td><td>[ \t\n\f\r]</td></tr> <tr><td>\S</td><td>[^ \t\n\f\r]</td></tr> </font></table></p>
<table[^>]*?>.*</table> won't match this unless you use /s
Next | Copyright © 2002 M. J. Dominus |