[ale] Yet another regex question

Joe Knapka jknapka at kneuro.net
Thu Aug 18 16:40:35 EDT 2005


Jason Day <jasonday at worldnet.att.net> writes:

> On Sat, Aug 13, 2005 at 05:53:16AM -0400, Christopher Fowler wrote:
> > On Sat, 2005-08-13 at 02:48 -0400, Jim Popovitch wrote:
> [snip]
> > > So, a regmatch of "[^ ]XMI001" would match "XMI001" and "zXMI001" but
> > > not " XMI001" since the brackets contain a negated space (i.e. no space
> > > before XMI001) 
> > 
> > I think the problem with that is that it requires something to be before
> > the X.  Something has to be there but no space.  I'm using perl to test
> > the ideas.
> 
> Try "[^ ]?XMI001".  That should match the string "XMI001" optionally
> preceded by any character that is not a space.  If you want to match 0
> or more non-spaces, use "[^ ]*XMI001".

But the string "   XMI001" *is* an instance of "XMI001" preceded by
zero non-space characters (and those zero non-spaces are preceded
by some spaces), so would match both of your expressions.

This definitely requires negative lookbehind, or else a multi-step
filter (get the lines containing "XMI001", then discard the ones
containing " XMI001"). "grep XMI001 [file] | grep -v ' XMI001'"
should do it. Except I think Chris said that the input is NOT
line-oriented, which means that no line-oriented filter is going
to be able to do the right thing.

-- Joe Knapka



More information about the Ale mailing list