Author Topic: Need help with regex syntax  (Read 1595 times)

JimmieC

  • Senior Community Member
  • Posts: 490
  • Hero Points: 17
Need help with regex syntax
« on: July 31, 2018, 07:54:14 PM »
I have some comm. captures that begin the line like this:
15:29:43.31 [COM54] - 01 00 91 29 02 01 33 53 33 34 35

I want to search for cases where "01 00 .. 29" do not occur after dash-space. That is they are not at the beginning of a capture line.

In Perl regex, I know that [^ ] means NOT character set. But what is need is NOT "- " (dash-space string).

I tried [^(- )]01 00 .. 29 and that did not work because I need to negate a string, not a character set.

I am sure this is childs-play for many on this forum so thanks in advance.

b

  • Senior Community Member
  • Posts: 325
  • Hero Points: 26
Re: Need help with regex syntax
« Reply #1 on: July 31, 2018, 08:34:22 PM »
First, Perl RE normally doesn't have negative matches (with the exception of inverted characters as you pointed out).  One would normally negate the match (e.g., in perl if $_ !~ /X/)

I know that I have gone to SE REs just because I needed negated REs.

With that said, the documentation suggests that you could use

(?!X)
True if X is not a match

Messing around with the regex evaluator, I finally got the following to work.  It may need refining to your needs.  Note, the \s (for space) was needed as leaving the bare space didn't work (bug, or defaults to the /x in perl's RE matching)

Looking at your output sample, I assumed you were matching hex values (thus use of the [[:xdigits:]]{2})

^(?!01\s00\s[[:xdigit:]]{2}\s29)([[:xdigit:]]{2}\s)+