Maybe what you want is a character set or a non-greedy match. You can read about both of these in perlre.
use strict; use warnings; use Data::Dumper; my $string = '<?test=6565?><?test=6566?>xxx<?test=6567?>'; my @array1 = $string =~ m/(<[^>]*>)/g; my @array2 = $string =~ m/(<.*?>)/g; print Dumper(\@array1); print Dumper(\@array2); __END__ $VAR1 = [ '<?test=6565?>', '<?test=6566?>', '<?test=6567?>' ]; $VAR1 = [ '<?test=6565?>', '<?test=6566?>', '<?test=6567?>' ];
update: If you need the work "test" to be in the matched string, then something like this:
use strict; use warnings; use Data::Dumper; my $string = '<?test=6565?><?some=6565?><?test=6566?><?other=6566?><?t +est=6567?><?data=6567?><?test=6568?>xxx<?test=6569?>'; my @array1 = $string =~ m/(<[^>]*test[^>]*>)/g; print Dumper(\@array1); __END__ $VAR1 = [ '<?test=6565?>', '<?test=6566?>', '<?test=6567?>', '<?test=6568?>', '<?test=6569?>' ];
In reply to Re: pattern match
by ig
in thread pattern match
by Selvakumar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |