
mhx
Enthusiast
Aug 26, 2001, 7:47 AM
Post #2 of 3
(14403 views)
|
Hey, cool, it seems there's someone really interested in regular expressions. There are several ways to achieve what you want. But, first of all,
$string1="a1 b2 c3"; ($find_string)=$string1=~/\w\d/; will always make $find_string equal 1, not 'a1'. So I'm sure you meant
($find_string)=$string1=~/(\w\d)/; If you supply a g modifier to the regex, it will return an array of all substrings matching the regex:
@find_strings = $string1 =~ /(\w\d)/g; Now @find_strings will contain all substrings, for the example this would be ('a1', 'b2', 'c3'). Another way would be to make a loop with the g-modifier:
while( $string1 =~ /(\w\d)/g ) { print "Substring found: $1\n"; } This will also find all matching substrings and is more useful if you want to catch several subexpressions, like
while( $string1 =~ /(\w)(\d)/g ) { print "Character: $1, Digit: $2\n"; } Hope this helps. -- Marcus P.S.: If you're interested in learning more about regexes, I recommend reading perldoc perlre. If you're still interested in learning more about regexes then, I recommend reading japhy's Regular Expressions in Perl and Jeffrey Friedl's Mastering Regular Expressions. And, of course, keep on posting questions to this forum if you need help!
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= ($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"
|