1

I am trying to find all the lines that contains part of a search string but also does not begin with "00000000". I am using this expression in Notepad++ but will also use it in another custom app that we use that also uses regular expressions.

I want to search for 118200000 00000000 0000000000 but I do not want to include the lines if it is preceded with 00000000 For example If I had:

01905402834          000000017090156300000000000118200000                               00000000   0000000000
01205028361          000000017090156300020381274118200000                               00000000   0000000000

I do not want to pick-up the first line because it has 00000000 just before 1182, but I rather just have the second line.

I thought of trying (?!00000000)118200000 00000000 0000000000, but that matches all, so obviously I am missing something or misusing the expression.

1
  • Welcome to SO! The formatting of the code on this question makes it difficult to determine your intent and requirements. Can you edit the question to clarify? (you can use Ctrl+K to indent code, or use triple backtick fences ```). Commented Jun 14, 2019 at 23:34

2 Answers 2

3

This pattern (?!00000000)118200000 00000000 0000000000 asserts what is directly on the right is not 00000000. That would always match as what comes after it is 118200000

If negative lookbehind is supported, you might prepend (?<!00000000) asserting what is on the left is not 00000000

(?<!00000000)118200000 00000000 0000000000

Regex demo

Sign up to request clarification or add additional context in comments.

6 Comments

Yes, that is exactly what I was missing! Thanks for the explanation and now I understand how it works.
Hmm, this seems to work in Notepad++ but not in our custom app because it interprets the "<" incorrectly in the expression. Is there an alternative to using the lookbehind character?
@DRobert One option is to match what you don't want and to capture what you want to keep so you can check for group 1 for example 00000000118200000|(118200000 00000000 0000000000) See demo
If I understand what you are suggesting and from what I tried in Notepad++ is that it is finding the opposite of what I am looking for. Unfortunately this would not work for our third-party app since this app is partly used to scrape logs and alert on certain conditions and it uses a single search string to capture the data to alert, so the inverse selection would not work in our case. The supplier of the app indicated that a newer version does not have the limitation with the "<" character, so we may need to upgrade if there are no other alternative solution.
I believe it uses the C++ regex engine but it is just a bug in their parsing that is causing to interpret the "<" and ">" as XML tag delimeters and therefore does not parse the regex string properly.
|
1

My guess is that you wish to only get lines that does not have 00000000, for which maybe we'd be starting with an expression similar to:

^(?!.*\b00000000\b.*).*

Demo

1 Comment

Hi Emma, That is not quite what I was looking for since I want to find lines that does not have 00000000 in front of the string 118200000 00000000 0000000000. Thanks for the suggestion though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.