I am looking for a solution to do this in Perl.
Example:
If my string is:
my $content = 'toto /app/blah titi\nhuh/app/ttt wew';
and my pattern is: /app/something I want to get as output in an array: /app/blah and /app/ttt.
(which is basically what grep -E -o '\/app\/[a-z]*' does)
I can’t get it work !
I tried:
my $content = 'toto /app/blah titi\nhuh/app/ttt wew';
$content =~ m/(\/app\/[a-z]*)/;
print "Group: $1 $2\n";
but this only prints: /app/blah (not /app/ttt)
and anyway, I don’t know how to put the results in a table:
my (@table) = @_;
the table does not contain anything!
thx
You want to use the
/gmodifier to make the regular expression return all the matches as a list:Also,
@_does not have anything to do with regular expressions. Rather, it is the list of parameters that was passed to the current subroutine.