in reply to Help with a regular expression for file name parsing
This works with the samples supplied:
print $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? print for $data =~ m[\@include\s('[^']+'|"[^"]+"|.+?(?<!\\))\s]g;; "some file" 'another file' yet\ another\ file
Spreading that out a bit:
m[ \@include \s ## the introducer followed by a space ( ## capture '[^']+' ## A single quoted string with no embedded single + quotes | ## or "[^"]+" ## a double quoted string with no embedded double + quotes | ## or .+? (?<!\\) ## a min length string that ends in a space that +isn't escaped ) \s ]gx;;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Help with a regular expression for file name parsing
by TJPride (Pilgrim) on Dec 07, 2011 at 11:30 UTC | |
by bontchev (Sexton) on Dec 07, 2011 at 12:07 UTC | |
by TJPride (Pilgrim) on Dec 07, 2011 at 13:23 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |