Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Help with a regular expression for file name parsing

by BrowserUk (Patriarch)
on Dec 07, 2011 at 07:11 UTC ( [id://942168]=note: print w/replies, xml ) Need Help??


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;;

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

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
    Your regular expression works, but the code is rather a muddle. Here's a version that he can use to test with:

    $data = join '', <DATA>; print "$_\n" for $data =~ m[\@include\s('[^']+'|"[^"]+"|.+?(?<!\\))\s] +g; __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?
      When tested with this version, the output is just 1
        Are you sure you copied it correctly? I get this:
        "some file" 'another file' yet\ another\ file
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://942168]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 01:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found