perlmonkdr has asked for the wisdom of the Perl Monks concerning the following question:
I'm looking to extract the expression that start with the CONSTANT, it could appear in any part and inside of any code, so i placed a couple of example to show you, the only "constant" part is the CONSTANT it self, the other part may vary between situation, let start:
#!/usr/bin/perl #this are a couple of example $_ = <<'REGEXP'; $one = CONSTANT . 'string' . $obj->new[0] . $variable . "string" . $ob +j->method("some".'thing'.$more); $some->method( CONSTANT . $obj->new[0] . 'string' . $obj->method("some".'thing'.$more +). $variable . "string" , "NOT INCLUDED" ); sub( CONSTANT . 'string' . $obj->new[0] . $variable . "string" . $obj->meth +od("some".'thing'.$more) ); REGEXP #let's magic begin! while (/ CONSTANT # begin the search with this string (?> #start looking but not return if fails "[^"]*" # catch every thing within double quotes | # or '[^']*' # catch every thing within single quotes | # or (\( # if its a parentheses (?> #start looking but not return if fails [^()]++ # catch every thing that is not a parentheses | # or (?1) # if its a parentheses make a recursion in it ) \))+ | #or same as above but looking square braket (\[ # if its a square braket (?> #start looking but not return if fails [^\[\]]++ # catch every thing that is not a square brak +et | # or (?2) # if its a square braket make a recursion in it ) \])+ | # or [a-zA-Z0-9_.\-\>\s\$]++ #looking only this string "." is po +int | # or (?R) # if those individual regexp fails, make a recursion, # only stop when all fails )* /xgo) { print "$&\n"; }
The problem with it, is the magic not begin, in fact, don't work at all
What i'm doing wrong?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: RegExp, the magic not begin
by JavaFan (Canon) on Sep 26, 2010 at 21:05 UTC | |
by perlmonkdr (Beadle) on Sep 26, 2010 at 22:06 UTC | |
by perlmonkdr (Beadle) on Sep 26, 2010 at 21:52 UTC | |
|
Re: RegExp, the magic not begin
by Anonymous Monk on Sep 26, 2010 at 19:51 UTC | |
by perlmonkdr (Beadle) on Sep 26, 2010 at 20:32 UTC | |
by Anonymous Monk on Sep 26, 2010 at 21:50 UTC |