Perl Regex Question

Ask

n00b
Joined
Apr 11, 2005
Messages
13
how would I print a line in perl that contains at least 3 digits somewhere in it but not necessarily in order please let me know if anyone can help!
 
I havent touched perl in like 4 years and even then I had no idea what I was doing, but boy on boy did I use regex.

I believe you want something along the lines of .*d+.*d+.*d+.* where d+ means one or more digits and .* means zero or more anything.

Edit: Just added perl to my cygwin to test it out, seems that you must put a slash infront of the d+. And depending on how you want your match you may want a .+

Code:
Example:
if ( $line=~/.+\d+.+\d+.+\d+.+/ )
	-will match three digits seperated by something.
	eg:" 10 20 30 " - will match 10, 20, and 30

if ( $line=~/.*\d+.*\d+.*\d+.*/ )
	-will match any three digits
	eg: " 123 " - will match 1, 2, 3
 
thanks, the second line is what i was looking for..
if ( $line=~/.*\d+.*\d+.*\d+.*/ )
-will match any three digits
eg: " 123 " - will match 1, 2, 3
thanks again
 
Back
Top