Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Capturing parenthesis and grouping square brackets

by ambrus (Abbot)
on Jun 18, 2013 at 09:09 UTC ( [id://1039534]=note: print w/replies, xml ) Need Help??


in reply to Capturing parenthesis and grouping square brackets

I think round parenthesis for captures is a good idea, for two resons.

The first is that perl makes simple things easy and complicated things possible. In simple regular expressions, capturing parenthesis occur more frequently than non-capturing ones. Once you write more complicated regexen with nested branches and the like, you have to learn the full syntax.

The second is that in simple cases, you can use capturing parenthesis for parts of a regex that you don't want to capture, and just not refer to them later. In most programs this won't cause too much problems, extra capture groups gets a maintenance burden only when you use large regexen with lots of parenthesis, in which case you probably want named captures anyway, or could become a slight performance problem if you're micro-optimizing your script, and in both of these cases you should learn the full syntax and other details about the regex engine.

The original reason for round parenthesis is simply historical. Round parenthesis were always capturing in ed and sed and awk and ex (they're spelt \( \) in ed and sed and ex though), and I think in ancient perl too, whereas non-capturing parenthesis are a newer invention.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-24 18:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found