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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.