This has been dogging me for some time. Here is the data:

$data = 'Win32::TieRegistry(Delimiter=>"/")'; $data = "Acme::Beatnik"; $data = "CGI qw(:all)"; $data = "Win32::API::Type"; $data = "DBI";
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 =~ /(\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

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.