Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Capturing parenthesis and grouping square brackets

by ambrus (Abbot)
on Jun 18, 2013 at 09:09 UTC ( #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.


Comment on Re: Capturing parenthesis and grouping square brackets
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2014-09-23 02:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls