#!/usr/bin/perl #this are a couple of example $_ = <<'REGEXP'; $one = CONSTANT . 'string' . $obj->new[0] . $variable . "string" . $obj->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->method("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 braket | # or (?2) # if its a square braket make a recursion in it ) \])+ | # or [a-zA-Z0-9_.\-\>\s\$]++ #looking only this string "." is point | # or (?R) # if those individual regexp fails, make a recursion, # only stop when all fails )* /xgo) { print "$&\n"; }