Re: regular expression question

Scott Nicol <snicol@apk.net>
10 Jun 2005 22:13:20 -0400

          From comp.compilers

Related articles
regular expression question gvheurn@gmail.com (Gijs) (2005-06-08)
Re: regular expression question gah@ugcs.caltech.edu (glen herrmannsfeldt) (2005-06-08)
Re: regular expression question 148f3wg02@sneakemail.com (Karsten Nyblad) (2005-06-08)
Re: regular expression question daw@taverner.cs.berkeley.edu (2005-06-08)
Re: regular expression question gvheurn@gmail.com (Gijs) (2005-06-09)
Re: regular expression question nicola.musatti@gmail.com (Nicola Musatti) (2005-06-09)
Re: regular expression question cfc@shell01.TheWorld.com (Chris F Clark) (2005-06-09)
Re: regular expression question snicol@apk.net (Scott Nicol) (2005-06-10)
Re: regular expression question snicol@apk.net (Scott Nicol) (2005-06-10)
Re: regular expression question d148f3wg02@sneakemail.com (Karsten Nyblad) (2005-06-10)
Re: regular expression question torbenm@diku.dk (2005-06-10)
Re: regular expression question skandgoe@gwdg.de (Skandinavisches Seminar) (2005-06-10)
Re: regular expression question mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2005-06-12)
| List of all articles for this month |
From: Scott Nicol <snicol@apk.net>
Newsgroups: comp.compilers
Date: 10 Jun 2005 22:13:20 -0400
Organization: Compilers Central
References: 05-06-045 05-06-054
Keywords: lex
Posted-Date: 10 Jun 2005 22:13:20 EDT

Nicola Musatti wrote:
> Gijs wrote:
> [...]
>
>>So for example I want to have a RE that matches all strings except for
>>the string "hello". How do you do this?
>
>
> How about something like:
>
> . | .. | ... | .... | [^h][^e][^l][^l][^o] | ......*
>
> i.e. accept all strings of length different from 5 and all strings of
> length 5 that are not "hello" (I have to confess that I did read the
> other messages in this thread :-).


Your RE won't work correctly for a few reasons. First, your last term
should have seven dots, since the last one is zero-or-more. Second,
the expression isn't anchored, so the first "." will match anything.
Third, the [^h][^e][^l][^l][^o] knocks out any 5-character term with
at least one matching character in the right position, like:


hairy
meter
bolts
mauls
blamo


A correct expression that you could pass straight into egrep:


^((.?.?.?.?)|([^h]....)|(.[^e]...)|(..[^l]..)|(...[^l].)|(....[^o])|(.......*))$


--
Scott Nicol
snicol@apk.net



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.