my $braces = qr{
\(
(?:
(?> [^\(\)"]+ ) # Non-parens without backtracking
|
(?> "[^"]*")+ # skip string constants
|
(??{ $braces }) # Group with matching parens
)*
\)
}x;
my $Braces = qr{\(((?:[^\(\)"]+|"[^"]*")*(?:$braces(?:[^\(\)"]+|"[^"]*")*)*)\)};
my $str = 'foo( FieldName, trim(CStr(Request.Form(FieldName))), CountryId )';
$str =~ $Braces and print "YES: $1\n" or print "NO!\n";
####
YES: CStr(Request.Form(FieldName))
####
YES: FieldName, trim(CStr(Request.Form(FieldName))), CountryId
####
This is perl, v5.8.0 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2002, Larry Wall
Binary build 805 provided by ActiveState Corp. http://www.ActiveState.com
Built 18:08:02 Feb 4 2003