Thoughts regular expressions in, for example sed
Colin Watson
cjwatson at ubuntu.com
Sat Jan 12 13:22:31 UTC 2013
On Fri, Jan 11, 2013 at 11:43:02PM +0100, Johnny Rosenberg wrote:
> I don't know if regular expressions are used the same way in all those
> nice tools, like sed, grep and whatever, but I can't stop wondering
> why the regular expression syntax is so inconsistent.
>
> Some characters are used for things, so if I want to search for them I
> need to escape them, for example ”.\[]{}”, but what about ()? They are
> the other way around: I have to escape them when I want to use them!
> Why is this?
If you want a somewhat more consistent syntax, use extended regular
expressions (e.g. with 'sed -r', which is a GNU sed extension).
The answer to your question is probably simply that the regular
expression language used in Unix tools evolved organically over time
rather than being designed in one go.
--
Colin Watson [cjwatson at ubuntu.com]
More information about the ubuntu-users
mailing list