in reply to Re^4: Need some help with Regex
in thread Need some help with Regex
That may not be doing what you expect! Consider:
#!/usr/bin/perl use strict; use warnings; for my $tail ('Z.z', '1.z', 'a(x)z', 'aaa', 'aa_', 'xxx@') { my $str = "name = $tail"; if ($str =~ /name\s*=\s*([A-Za-z].+\w)/) { print "Matched >$1< in >$str<\n"; } else { print "No match for >$str<\n"; } }
Prints:
Matched >Z.z< in >name = Z.z< No match for >name = 1.z< Matched >a(x)z< in >name = a(x)z< Matched >aaa< in >name = aaa< Matched >aa_< in >name = aa_< Matched >xxx< in >name = xxx@<
[A-Za-z] matches a single letter. .+ matches at least one characters and as many as it possibly can such that the remainder of the regular expression matches. \w matches a single alphanumeric or underscore character.
|
|---|