I need to parse a bunch of single-line text that follow a similar format:
This is an example instance [link[filename1|path_to_file1]] that I need to parse [link[filename2|path_to_file2]]. Here is another [link[filename3|path_to_file3]] and so on [link[filename4|path_to_file4]]
I want to regex for every text before and after the |
symbol.
I have the following regex:
while ( my @row = $sth->fetchrow_array() ) {
my $line = $row[4];
if($line =~ /\[link\[(.*?)\|(.*?)\]?\]/g){
print "MATCH1: $1\n";
print "MATCH2: $2\n";
}
}
Unfortunately, it will only return me the first instance (filename1
, path_to_file1
). How can I change it so all instances are captured?
I would like the following output:
MATCH1:filename1
MATCH2:path_to_file1
MATCH1:filename2
MATCH2:path_to_file2
MATCH1:filename3
MATCH2:path_to_file3
MATCH1:filename4
MATCH2:path_to_file4