Amblikai has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regex for ignoring paths
by haukex (Archbishop) on Oct 31, 2018 at 11:21 UTC | |
by Amblikai (Scribe) on Oct 31, 2018 at 13:34 UTC | |
Re: Regex for ignoring paths
by harangzsolt33 (Deacon) on Oct 31, 2018 at 14:48 UTC | |
by Anonymous Monk on Oct 31, 2018 at 20:39 UTC | |
by harangzsolt33 (Deacon) on Nov 01, 2018 at 02:44 UTC | |
by Anonymous Monk on Nov 01, 2018 at 06:25 UTC | |
Re: Regex for ignoring paths
by dbuckhal (Chaplain) on Oct 31, 2018 at 18:05 UTC | |
by Anonymous Monk on Oct 31, 2018 at 18:12 UTC | |
by dbuckhal (Chaplain) on Oct 31, 2018 at 19:26 UTC |