use strict;
my $str = 'Not even sure how to attack this Regex Need (Multiline text with extraction of library names)
Sample Text
box::use(
DBI[dbListTables, dbExecute],
Yessir[this_one, that one,
and_this_one],
Maybesir[
func_one,
func_two,
],
Nosir,
database = logic/database,
log = logic/log,
options = logic/options,
utilities = logic/utilities,
)
I would like to have a regexp which matches the following from the above text:
DBI, Yessir, Maybesir, Nosir
Is there an easy way to approach this? I have been trying to use the regexp101 website to help me out here, but this one is sufficiently complex that I am a bit out of my depth. My current line is the following:
box::use\\(\\n(?:[\\s]*([A-Za-z0-9]*)(?:[A-Za-z0-9\\[\\]_\\ ,]*\\n))
But, this is of course not getting it. I am not sure how to handle getting the multiple (unknown how many there really would be) libraries inside the box::use function.
It might be easier to extract the text from inside the use::box function first and then regexp that?
Edit: Forgot to add that I am using Python3';
my $regex = qr/(?:\b\w++::\w++\s*+\(|\G(?<!^))\s*+(\w++)\s*+(?:\[[^]]*+]\s*+)?,/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html