# Regex Grouping Question

1. Mar 25, 2012

### sunmaz94

I was just playing around with sed regular expressions and found something I wouldn't have expected.

What is the difference between /\.[^.]*$/ and /(\.[^.]*)$/?
Does the latter group it incorrectly somehow.
Note that the former does what I want it to, to match an extension of a file, whilst the latter does not.

2. Mar 25, 2012

### D H

Staff Emeritus
It depends on how you use sed, and which sed you use. Older versions of sed use basic regular expressions. You need to backslash escape the parentheses to make them grouping characters. Even older versions of sed don't even have groups. Modern versions of sed allow extended regular expressions, enabled via the -E option to sed. This makes parentheses are grouping characters (and need to be backslash-escaped to make them ordinary characters).

3. Mar 25, 2012

### sunmaz94

That clears things up significantly. Thanks!

4. Mar 25, 2012

### Hobin

Incidentally, this is one of the reasons one shouldn't play around with sed on system configuration files using only a very general tutorial on how sed is supposed to work.

(Hey, I was 13 then! )

5. Mar 30, 2012

### DaleSwanson

Any time I'm working with regex I find this site very useful:
http://www.regextester.com/