in reply to Re^2: Help with a regular expression for file name parsing
in thread Help with a regular expression for file name parsing
Sigh, the site mangled the code I posted. :-( I guess I've used the wrong tag. Let's try again:
use strict; use warnings; while (my $data = <DATA>) { if ($data =~ /\@include/i) { $data =~ m/\@include\s+('[^']+'|"[^"]+"|.+?(?<!\\))\s/gi; my $fname = $1; $fname =~ s/\\([rnt'"\\ ])/"qq|\\$1|"/gee; $fname =~ s/^"(.*)"$/$1/s or $fname =~ s/^'(.*)'$/$1/s; print "File name: <$fname>\n"; } } __DATA__ #some "random stuff" @include "some file" did you parse that? #more 'random' stuff @include 'another file' you sure? #and more random stuff @include yet\ another\ file positive? #@Include file # @include "\"another one\"" hmmm... # some stuff
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Help with a regular expression for file name parsing
by BrowserUk (Patriarch) on Dec 09, 2011 at 09:35 UTC |
In Section
Seekers of Perl Wisdom