Regular expression pattern explanation

I’m fairly new to regular expressions, I recently used a regular expression in a perl script, and I can’t figure it out:

$groups= qr/\(([^()]+|(??{$groups}))*\)/;

Any help will be greatly appreciated!

Well, if you expand it:

$groups = qr/
\( # match an open paren (
(# followed by
[^()]+ # one or more non-paren character
| # OR
(??{$groups}) # the regex itself
)* # repeated zero or more times
\) # followed by a close paren )
/x;

You will get an elegant recursive method to find balanced brackets:)

I am fairly new to regular expressions, I recently I used a regular expression in the perl script and I can’t figure it out:

$groups= qr/\(([^()]+|(? ?{$groups}))*\)/;

Any help would be greatly appreciated!

Well, if you extend it:

$groups= qr/
\( # match an open paren (
(# followed by
[^()]+ # one or more non-paren character
| # OR
(?? {$groups}) # the regex itself
)* # repeated zero or more times
\) # followed by a close paren )
/x;

You will Get an elegant recursive method to find balanced brackets:)

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5472 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.