user1739581
user1739581

Reputation: 85

Notepad++ search combination in lines

I am looking for a specific combination in a txt file that contains multiple lines (Notepad ++). The structure of a line I am looking for is as follows:

xxxxxx  N  N  -1  -1  -1  N (end line)

So I first have an identifier of 6 or more characters, followed by 6 numbers (N) spaced by a tab. N can be values 1, 0 or -1. I am looking for those lines that contain '-1' in position 3, 4 and 5. The other positions can take any of the 3 values. I have searched online and applied searches such as:

\t-?\t-?\t-1\t-1\t-1\t-?

\t?.\t?.\t-1\t-1\t-1\t?.

t?.\t?.\t-1\t-1\t-1\t?.\n

\t-1\t-1\t-1\t?.\n

Yet, the last N in the line is not taken into account, so that if its value is 0 for example, that line will not be selected.

What is the way to write this search? I understand Notepad ++ is written in C++.

Upvotes: 0

Views: 719

Answers (2)

DigitalNomad
DigitalNomad

Reputation: 1041

You can try the following regex:

^[a-zA-Z0-9]+\t(-1|0|1)\t(-1|0|1)\t[\-][1]\t[\-][1]\t[\-][1]\t(-1|0|1)$

I tried on the following sample and it worked for me.

  xxxxxx    1   1   -1  -1  -1  1
  xxxxxx    0   1   -1  -1  -1  0
  test12    -1  1   -1  1   -1  0
  xxxxxx    1   1   -1  -1  -1  0
  test13    0   1   -1  -1  1   -1

Hope it helps.

Upvotes: 0

mayo
mayo

Reputation: 4095

Can you try to follow this pattern?:

^([a-zA-Z0-9]{6,})\s*(-1|0|1)\s*(-1|0|1)\s*((-1\s*?){3})\s*(-1|0|1)\s?

https://regex101.com/r/yM5xD3/2


Explanation:

^: Start of the line.

([a-zA-Z0-9]{6,}): Any character six or more times.

\s*: space/tab/newLine zero o more times.

(-1|0|1): One of those numbers.

\s*: ...

(-1|0|1): One of those numbers.

((-1\s*?){3}): -1 one time followed by space/tab/newLine zero or more times. (The '?' means that the regex will try to get the less amount of \s as possible)

\s*: ..

(-1|0|1): ...

And the last \s?: looks for zero or one Space/tab/newLineCharacter

Upvotes: 1

Related Questions