I want to match the module name (bareword) and not the list, which may or may not be present as in the last scalar. The problem is the double colons. Here was my first attempt:$data = 'Win32::TieRegistry(Delimiter=>"/")'; $data = "Acme::Beatnik"; $data = "CGI qw(:all)"; $data = "Win32::API::Type"; $data = "DBI";
$data =~ /(\w+.*?)(\s*|\()/;
The problem is the dot symbol doesn't match a colon. So here was my second attempt:
$data =~ /(\w+[.:]*?)(\s*|\()/;
Still doesn't match the colon. Third attempt:
$data =~ /(\w+[.*:*]?)(\s*|\()/;
But this only matches the first colon. Getting closer! So I thought: I want to match every alphanumeric character or double colons followed by more alphanumeric characters (and possibly more double colons followed by ...), so maybe I should use the pipe symbol. Fourth attempt:
$data =~ /(\w+(.|::.*)*?)(\s*|\()/;
That's when I realized this is getting silly. Should I be using look aheads?
In reply to Regexp Question by jacques
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |