Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Regex to pull out string within parentheses that could contain parentheses

by hippo (Bishop)
on Jul 09, 2018 at 14:23 UTC ( [id://1218167]=note: print w/replies, xml ) Need Help??


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');
  • Comment on Re: Regex to pull out string within parentheses that could contain parentheses
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1218167]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-24 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found