You're close. I added strict and warnings, moved the regex into a while loop, added the /g modifier to get all matches, and deleted $2 since you only have one set of capturing parentheses (see perlre). I didn't touch the regex itself, but please note that \w matches "word" characters (alphanumeric plus "_"). If this is sufficient, you could improve the readability of the regex by using it instead of the character classes.
Output:use strict; use warnings; my $text = "test1 zzzzzzzzzzzzzzz test2 test3 test4 test5 zzzzzzzzzzzz +zzz test6 test7 zzzzzzzzzzzzzzz test8 test9 test10"; while( $text =~ /([a-zA-Z0-9]+\s+[z]{15}\s+[a-z0-9]+)/g ) { print "string: " . $1 . "!\n"; }
string: test1 zzzzzzzzzzzzzzz test2! string: test5 zzzzzzzzzzzzzzz test6! string: test7 zzzzzzzzzzzzzzz test8!
In reply to Re: regex question
by bobf
in thread regex question
by goff
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |