| Author |
Looking for regular expression
|
|
| Augustus S.F.X Van Dusen 2004-09-29, 8:09 pm |
| I would be interested in a POSIX 1003.2 regular expression (the ones
supported by the GNU regex package) such that it matches anything but a
fixed sequence of characters. My understanding is that
[^abc]
will match anything but any of a, b or c. That is, it will not match e.g.
bca. What I am after is a regular expression such that it would match
anything but exactly the abc sequence.
Any suggestions?
| |
| Michael Tosch 2004-09-29, 8:09 pm |
| In article <pan.2004.09.29.17.12.16.814035@story.net>, "Augustus S.F.X Van Dusen" <asfxvd@story.net> writes:
> I would be interested in a POSIX 1003.2 regular expression (the ones
> supported by the GNU regex package) such that it matches anything but a
> fixed sequence of characters. My understanding is that
>
> [^abc]
>
> will match anything but any of a, b or c. That is, it will not match e.g.
> bca. What I am after is a regular expression such that it would match
> anything but exactly the abc sequence.
>
> Any suggestions?
>
Wouldnt it be much simpler to search for 'abc' and negate it?
Such as
grep -v abc
or
sed '/abc/d'
or
awk '!/abc/{print $0}'
--
Michael Tosch
IT Specialist
HP Managed Services
Technology Solutions Group
Hewlett-Packard GmbH
Phone: +49 2407 575 313
Mail: michael.tosch:hp.com
| |
| Augustus S.F.X Van Dusen 2004-09-29, 8:09 pm |
| On Wed, 29 Sep 2004 17:31:22 +0000, Michael Tosch wrote:
> Wouldnt it be much simpler to search for 'abc' and negate it?
It would but, alas, I am using the regex API directly, not via a command
line utility.
> Such as
> grep -v abc
> or
> sed '/abc/d'
> or
> awk '!/abc/{print $0}'
| |
| William Park 2004-09-29, 8:09 pm |
| Augustus S.F.X Van Dusen <asfxvd@story.net> wrote:
> On Wed, 29 Sep 2004 17:31:22 +0000, Michael Tosch wrote:
>
>
>
> It would but, alas, I am using the regex API directly, not via
> a command line utility.
Try
([^a]..|.[^b].|..[^c])
--
William Park <opengeometry@yahoo.ca>
Open Geometry Consulting, Toronto, Canada
| |
| Augustus S.F.X Van Dusen 2004-09-29, 8:09 pm |
| On Wed, 29 Sep 2004 18:10:12 +0000, William Park wrote:
> Augustus S.F.X Van Dusen <asfxvd@story.net> wrote:
>
> Try
> ([^a]..|.[^b].|..[^c])
Thanks. The generalization to more characters is a bit awkward,
unfortunately. But, thanks again.
| |
| Laurent Schneider 2004-10-02, 9:12 pm |
| grep -v abc
is
grep '^([^a]|a([^b]|$)|ab([^c]|$))*$'
Regards
Laurent
| |
| Stephane CHAZELAS 2004-10-02, 9:12 pm |
| 2004-09-30, 05:20(-07), Laurent Schneider:
> grep -v abc
> is
> grep '^([^a]|a([^b]|$)|ab([^c]|$))*$'
[...]
No.
$ echo aabc | egrep '^([^a]|a([^b]|$)|ab([^c]|$))*$'
aabc
$ echo aabc | egrep -v abc
$
^([^a]|a*a[^ab]|[ab]*b(a*a[^ab]|[^ac]))*[ab]*$
Should be better. See
http://groups.google.com/groups?sel...hazelas.free.fr
--
Stephane
| |
| Laurent Schneider 2004-10-02, 9:12 pm |
| and
grep -v ^abc$
is
grep '^($|[^a].*|a([^b].*|$)|ab([^c].*|c.|$))$'
PS: grep -E on my system
| |
| Laurent Schneider 2004-10-02, 9:12 pm |
| > You may need to backslash-escape some or all of "()|?":
> ^([^a].*|a([^b].*|b([^c].*|c..*)?)?)?$
>
>
> paul
the answer above is correct and is equivalent to
^($|[^a].*|a([^b].*|$)|ab([^c].*|c.|$))
sorry for my inexact answer before
| |
| Stephane CHAZELAS 2004-10-02, 9:12 pm |
| 2004-09-30, 05:32(-07), Laurent Schneider:
> and
> grep -v ^abc$
> is
> grep '^($|[^a].*|a([^b].*|$)|ab([^c].*|c.|$))$'
[...]
or
grep -E '^([^a]|.[^b]|..[^c]|.{4,}|.{0,2})$'
should work with more versions of egrep (some don't like the "$"
not in last place).
--
Stephane
| |
| Stephane CHAZELAS 2004-10-02, 9:12 pm |
| 2004-09-30, 13:00(+00), Stephane CHAZELAS:
[...]
> grep -E '^([^a]|.[^b]|..[^c]|.{4,}|.{0,2})$'
[...]
Forget it.
grep -E '^(([^a]|.[^b]|..[^c]).*)|.{4,}|.{0,2})$'
--
Stephane
| |
| Augustus S.F.X Van Dusen 2004-10-02, 9:13 pm |
| On Wed, 29 Sep 2004 17:31:22 +0000, Michael Tosch wrote:
> Wouldnt it be much simpler to search for 'abc' and negate it?
It would but, alas, I am using the regex API directly, not via a command
line utility.
> Such as
> grep -v abc
> or
> sed '/abc/d'
> or
> awk '!/abc/{print $0}'
| |
| William Park 2004-10-02, 9:13 pm |
| Augustus S.F.X Van Dusen <asfxvd@story.net> wrote:
> On Wed, 29 Sep 2004 17:31:22 +0000, Michael Tosch wrote:
>
>
>
> It would but, alas, I am using the regex API directly, not via
> a command line utility.
Try
([^a]..|.[^b].|..[^c])
--
William Park <opengeometry@yahoo.ca>
Open Geometry Consulting, Toronto, Canada
| |
| Paul Jarc 2004-10-02, 9:13 pm |
| "Augustus S.F.X Van Dusen" <asfxvd@story.net> wrote:
> What I am after is a regular expression such that it would match
> anything but exactly the abc sequence.
You may need to backslash-escape some or all of "()|?":
^([^a].*|a([^b].*|b([^c].*|c..*)?)?)?$
paul
| |
| Augustus S.F.X Van Dusen 2004-10-02, 9:13 pm |
| On Wed, 29 Sep 2004 18:10:12 +0000, William Park wrote:
> Augustus S.F.X Van Dusen <asfxvd@story.net> wrote:
>
> Try
> ([^a]..|.[^b].|..[^c])
Thanks. The generalization to more characters is a bit awkward,
unfortunately. But, thanks again.
| |
| Laurent Schneider 2004-10-02, 9:13 pm |
| > You may need to backslash-escape some or all of "()|?":
> ^([^a].*|a([^b].*|b([^c].*|c..*)?)?)?$
>
>
> paul
the answer above is correct and is equivalent to
^($|[^a].*|a([^b].*|$)|ab([^c].*|c.|$))
sorry for my inexact answer before
| |
| Stephane CHAZELAS 2004-10-02, 9:13 pm |
| 2004-09-30, 05:32(-07), Laurent Schneider:
> and
> grep -v ^abc$
> is
> grep '^($|[^a].*|a([^b].*|$)|ab([^c].*|c.|$))$'
[...]
or
grep -E '^([^a]|.[^b]|..[^c]|.{4,}|.{0,2})$'
should work with more versions of egrep (some don't like the "$"
not in last place).
--
Stephane
| |
| Laurent Schneider 2004-10-04, 6:01 pm |
| Stephane CHAZELAS <this.address@is.invalid> wrote in message news:<slrnclnv3b.23k.stephane.chazelas@spam.is.invalid>...
> 2004-09-30, 05:20(-07), Laurent Schneider:
> [...]
>
> No.
>
> $ echo aabc | egrep '^([^a]|a([^b]|$)|ab([^c]|$))*$'
> aabc
> $ echo aabc | egrep -v abc
> $
>
>
> ^([^a]|a*a[^ab]|[ab]*b(a*a[^ab]|[^ac]))*[ab]*$
>
> Should be better. See
> http://groups.google.com/groups?sel...hazelas.free.fr
ok stephan, thanks for your link, I see it is not your first try :-)
|
|
|
|