Looking for regular expression
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > Looking for regular expression




Pages (2): [1] 2 »   Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Looking for regular expression  
Augustus S.F.X Van Dusen


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-30-04 01:09 AM

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?








[ Post a follow-up to this message ]



    Re: Looking for regular expression  
Michael Tosch


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-30-04 01:09 AM

In article <pan.2004.09.29.17.12.16.814035@story.net>, "Augustus S.F.X Van Dusen" <asfxvd@st
ory.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







[ Post a follow-up to this message ]



    Re: Looking for regular expression  
Augustus S.F.X Van Dusen


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-30-04 01:09 AM

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}'






[ Post a follow-up to this message ]



    Re: Looking for regular expression  
William Park


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-30-04 01:09 AM

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





[ Post a follow-up to this message ]



    Re: Looking for regular expression  
Augustus S.F.X Van Dusen


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-30-04 01:09 AM

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.






[ Post a follow-up to this message ]



    Re: Looking for regular expression  
Laurent Schneider


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-03-04 02:12 AM

grep -v abc
is
grep '^([^a]|a([^b]|$)|ab([^c]|$))*$'

Regards
Laurent





[ Post a follow-up to this message ]



    Re: Looking for regular expression  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-03-04 02:12 AM

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...f
ree.fr

--
Stephane





[ Post a follow-up to this message ]



    Re: Looking for regular expression  
Laurent Schneider


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-03-04 02:12 AM

and
grep -v ^abc$
is
grep '^($|[^a].*|a([^b].*|$)|ab([^c].*|c.|$))$'

PS: grep -E on my system





[ Post a follow-up to this message ]



    Re: Looking for regular expression  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-03-04 02:12 AM

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






[ Post a follow-up to this message ]



    Re: Looking for regular expression  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-03-04 02:12 AM

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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:15 PM.      Post New Thread    Post A Reply      
Pages (2): [1] 2 »   Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register