in reply to Regex to pull out string within parenthesis that could contain parenthesis
Is this the sort of thing you are after? It's a PoC as it stands so feel free to tweak until it delivers what you actually want.
use strict; use warnings; use Test::More tests => 6; my $text = 'function convert_wa_date_strings(iv_beg string, iv_end str +ing, iv_read_date date, iv_step char(6)) returns (date, date, char(1) +)'; my $re = qr#^(private|public)?\s?(function|report)\s(\w+)\((.+?)\)((?: +\s+)(returns)\s\((.+)*?\))?$#; ok ($text =~ $re, 'Matched'); is ($1, undef, '$1 is correct'); is ($2, 'function', '$2 is correct'); is ($3, 'convert_wa_date_strings', '$3 is correct'); is ($4, 'iv_beg string, iv_end string, iv_read_date date, iv_step char +(6)', '$4 is correct'); is ($5, ' returns (date, date, char(1))', '$5 is correct');
|
|---|