First of all...
The problem is the dot symbol doesn't match a colon. So here was my second attempt:
...that's not true, . will match a ":" -- but you've said match zero or more of any character, and be non-greedy about it, so it is happily matching "zero" characters for the .*?, and zero white-space charaters for the \s*, and calling it a day.
Second of all: you said you "want to match the module name (bareword) and not the list" -- but it really looks like what you ment is that you want to "capture" the module name in $1, your regexps are making effor to match on other things after the name.
It seems like the most straight forward way to accomplish what you wnat is to ignore the multitudes of ways that a list might be put on the end, and just look for what you want: word characters, or colons...
bester:~> perl -le 'print $1 if "Win32::TieRegistry(Delimiter=>\"/\")" + =~ /([\w:]+)/;' Win32::TieRegistry
...if you have some reason to really be strict about only accepting words seperated by double-colons, then be strict...
bester:~> perl -le 'print $1 if "Win32::Tie::Reg:istry(Delimiter=>\"/\ +")" =~ /(\w+(::\w+)+)/;' Win32::Tie::Reg
bester:~> perl -le 'print $1 if "Win32::Tie::Reg:istry(Delimiter=>\"/\ +")" =~ /(\w+(::\w+)*)/;' Win32::Tie::Reg
UPDATE: Albannach pointed out that there probably should be a * in my second example to make it work on package names without any colons at all, like CGI.
In reply to Re: Regexp Question
by hossman
in thread Regexp Question
by jacques
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |