Hi Monks, i'm having a problem coming up with a nice regex for a quick script i'm writing

Essentially i'm parsing a file for certain pieces of information, and contained in the file is a unix path which triggers my regex

probably best explained with simplified code:

my $line=do { local $/=undef; <DATA>; }; my @substrings=$line=~/(\w+\.\w+)/g; print "$_\n" foreach(@substrings); __DATA__ Path to file: /users/me/foo.baz/filename.ext my_content(word.other)

Which obviously gives me:

foo.baz filename.ext word.other

The problem i have is that i'd like to only pick up "word.other"

I've tried: /(?<!\/)(\w+\.\w+) but that just (rightly) gives me "ord.other" and "oo.baz" etc

Obviously i could strip out the paths first etc but it seems like there should be a nice way to do it in a regex, i just can't think of one. Any thoughts? Thanks!


In reply to Regex for ignoring paths by Amblikai

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.