| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
On 27 Jun 2014 12:53:17 -0700, "[email protected] [sed-users]"
<[email protected]> wrote:
> I am trying to understand the working of ^ and $ in the middle of a
> regexp with gnused 4.2.1. The help file says they are considered as
> normal characters (except at start and end of sub expressions).
>
> This can be checked with (xa^by in input.txt):
>
>
> sed -n -e "/a^b/p" input.txt
> sed -n -e "/\(a^b\)/p" input.txt
>
>
> However when using the -r switch, none of the previous commands work as
> expected:
>
> sed -r -n -e "/a^b/p" input.txt
> sed -r -n -e "/(a^b)/p" input.txt
>
>
>
> This is puzzling. Am I missing something?
Without checking, I seem to remember that when using basic RE (the default
if you don't use -r), the ^ and $ anchors are special only if they appear
respectively at the beginning and at the end of a subexpression and normal
characters otherwise, whereas with extended RE (those you get with -r/-E)
they are always special.
So in short, the difference in behavior is expected.
--
D.