jacques has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regexp Question
by simonm (Vicar) on Aug 12, 2003 at 23:40 UTC | |
by jacques (Priest) on Aug 12, 2003 at 23:44 UTC | |
|
Re: Regexp Question
by hossman (Prior) on Aug 12, 2003 at 23:45 UTC | |
by jacques (Priest) on Aug 13, 2003 at 00:06 UTC | |
|
Re: Regexp Question
by Aristotle (Chancellor) on Aug 13, 2003 at 01:17 UTC |