CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Regular Expressions:


New User

Jul 19, 2008, 10:00 PM

Post #1 of 2 (10044 views)
/\((\([^)]*\))\)/ Can't Post

Could someone help me parse this. I have the basic idea, but am really confused on the details (particularly the group paren and the stuff inside the single character brackets):


/ - start of the regex

\( - escaped open paren

( - grouping paren (not sure why we need it though)

\( - second escaped paren

[ - single character? Not sure why?

^ - beginning of the line? now i am really confused. How do you have a beginning of line after two parens?

) - end grouping paren

] - end single char

* - have 0 or more of the single char (not sure what the single char was!

.... so forth....

I got this from a quiz to parse a madlib file that had questions in it of the following form:

I wanted to eat ((a number)) hamburgers.

Any explanation would be appreciated!


Jul 20, 2008, 10:42 AM

Post #2 of 2 (10021 views)
Re: [ball] /\((\([^)]*\))\)/ [In reply to] Can't Post

the pattern in the center is a negated character class:


the ^ is not the beginning of line anchor in this context, it means to not match whatever is inside the square brackets, in this case there is a sinlge right parenthesis ')'.

So essentially it means to match zero or more of anything except a ')'. Its appears to be capturingwhatever is inside of double parenthesis:

$_ =  '((this will match))'; 
print $1;

$1 is what is matched by the grouping parenthesis in the regexp.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives