in reply to Help with a regular expression for file name parsing
use strict; use warnings; my $data = join '', <DATA>; my $file; while ($data =~ m/\@include (".*?"|'.*?'|(?:[^\s\\]|\\ )+)/g) { $file = $1; $file =~ s/["'\\]+//g; print "$file\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?
CAVEAT: Assumes that ", ', and \ will never appear within filenames themselves. If they can, this gets much more complex.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Help with a regular expression for file name parsing
by bontchev (Sexton) on Dec 09, 2011 at 08:22 UTC | |
by bontchev (Sexton) on Dec 09, 2011 at 08:26 UTC | |
by BrowserUk (Patriarch) on Dec 09, 2011 at 09:35 UTC |