What is the difference between /\.[^.]*$/ and /(\.[^.]*)$/?

  • Thread starter Thread starter sunmaz94
  • Start date Start date
  • Tags Tags
    Grouping
AI Thread Summary
The discussion revolves around the differences between two regular expressions used in sed: /\.[^.]*$/ and /(\.[^.]*)$/. The first expression correctly matches file extensions, while the second does not due to grouping issues. The effectiveness of these expressions depends on the version of sed being used. Older versions require backslash-escaping parentheses for grouping, while modern versions support extended regular expressions with the -E option, where parentheses function as grouping characters. The conversation highlights the importance of understanding sed's variations across versions, especially when working with system configuration files, and recommends a regex testing site for further exploration.
sunmaz94
Messages
42
Reaction score
0
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.

Thanks in advance.
 
Technology news on Phys.org
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).
 
D H said:
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).

That clears things up significantly. Thanks!
 
D H said:
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).

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. :redface:

(Hey, I was 13 then! o:))
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top