[ale] Single out a alarm with regex

Christopher Fowler cfowler at outpostsentinel.com
Thu Oct 5 09:45:40 EDT 2006


I guess I was wanting a simple regex.

Here is what I do know about the alarm

1.  It starts with 'DCH:'
2.  There are any number of characters between the DCH and the type.
The type in the example is 'MAINT INDICATION'.
3.  I want every alarm with the exception of 'MAINT INDICATION'.

That is why I started out with the simple one.  I do not know how many
digits or even if they are digits that come after the DCH.  I do know
that it is at least one character.  

On Thu, 2006-10-05 at 09:34 -0400, Alex LeDonne wrote:
> On 10/4/06, Christopher Fowler <cfowler at outpostsentinel.com> wrote:
> > On Wed, 2006-10-04 at 16:05 -0400, Alex LeDonne wrote:
> > > On 10/4/06, Christopher Fowler <cfowler at outpostsentinel.com> wrote:
> > > > I've started with a regex that looks like this:
> > > >
> > > > '^(DCH:.*?(MAINT).*$)'
> > > >
> > > > The outer '(' are there so I can capture the whole thing in $1.
> > > >
> > > > what I'm trying to do is create a regex that will catch anything that
> > > > matches this format:
> > > >
> > > > DCH: 0 <TYPE> ....
> > > >
> > > > I want th whole line but I do not want it if the type is 'MAINT'.  What
> > > > I'm trying to do is get it to pass when the word MAINT is not in the
> > > > phrase.  Can someone give me a pointer?
> > > >
> > >
> > > Does the language/regex engine in question support zero-width negative
> > > lookahead assertions?
> > >
> > > '^(DCH: .*? (?!MAINT).*$)'
> >
> > I'm using standard PERL
> >
> > [cfowler at shuttle ~]$ echo "DCH: 0  MAINT INDICATION" | perl -le '$_ =
> > <STDIN>;print "Yes [$1]" if m/^(DCH:.*(?!MAINT).*$)/'
> > Yes [DCH: 0  MAINT INDICATION]
> >
> >
> > >
> > > I'm assuming that the space characters are part of the format. Use
> > > them to your advantage.
> 
> Your test does not include the space characters in the regex, so it's
> going to match the same as /^(DCH:.{2,}$)/. Also, the fact that spaces
> can appear in the trailing part is significant. Is the field after
> DCH: always digits? That could be helpful, too...
> 
> aledonne at rumba:~> echo "DCH: 0 MAINT INDICATION" | perl -le '$_ =
> <STDIN>; print "Yes [$1]" if m/^(DCH:\s+\d+\s+(?!MAINT).*$)/'
> aledonne at rumba:~> echo "DCH: 0 ERROR INDICATION" | perl -le '$_ =
> <STDIN>; print "Yes [$1]" if m/^(DCH:\s+\d+\s+(?!MAINT).*$)/'
> Yes [DCH: 0 ERROR INDICATION]
> 
> The more information you have about the format between DCH: and the
> zero-width negative lookahead, the more certain you can be about where
> it's anchored.
> 
> Also, this regex does assume that the last field in fact _begins_ with
> "MAINT"... some version of Jason's two-regex solution is much more
> sensible if you want to test the whole thing for  that substring.
> 
> -A
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale




More information about the Ale mailing list