The following utilizes the (?PARNO) feature introduced in perl 5.10 to create a recursive regex that captures balanced braces.
It could fail if there are braces included within strings in strange ways, but it should work fine for the way most people code:
use strict; use warnings; my $data = do {local $/; <DATA>}; if ($data =~ /(\s*{ [^{}]* \bfopen\b ((?: (?>[^{}]+) | {(?-1)} )*) })/ +x) { print $1; } __DATA__ void fo { ........ { //first one f = fopen(...); ....... if(...) { } } //mapping one ........ }
In reply to Re: a question about re
by wind
in thread a question about re
by SonicWang
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |