user6180951
user6180951

Reputation:

Notepad++ regex to find lines with more than n pipe-characters

once again I have a problem with a regex in Notepad++, since I don't know a lot about it.
I have a .csv file, but I need to find all lines with n (let's say 4) or more pipe-characters.
Example of the string I have:

6454345|User1-2ds3|62562012032|9c1fe63ccd3ab234892beaf71f022be2e06b6cd1
3305611|User2-42g563dgsdbf|22023001345|c36dedfa12634e33ca8bc0ef4703c92b73d9c433
8749412|User3-9|xgs|f|98906504456|411b0fdf54fe29745897288c6ad699f7be30f389
5151540|User4-jy|n|12202310|6a54c608289f4aedfab63ca640bcd5d174fd8592

I need to find these strings, they have 4 or more pipe-characters:

8749412|User3-9|xgs|f|98906504456|411b0fdf54fe29745897288c6ad699f7be30f389 
5151540|User4-jy|n|12202310|6a54c608289f4aedfab63ca640bcd5d174fd8592 

I did some searches here but couldn't find exactly what I am looking for, so far I used the answers provided in these questions, besides that I didn't find anything similar:
Find Lines with N occurrences of a char
Regular expression to match text that contains n or more of specified character
I replaced the requested characters in a pipe-character, but that didn't work for me.

Upvotes: 2

Views: 3730

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627199

You may use either of the two expressions below to match line that have 4 pipes:

^(.*?\|){4}

or

^([^|\r\n]*\|){4}

Note that you need to have . matches newline option OFF to make the first pattern work.

Pattern details:

  • ^ - start of line
  • (.*?\|){4} - 4 occurrences of any chars other than line break chars, as few as possible, up to the first | and then a | char
  • [^|\r\n] - matches any char but a |, CR and LF symbols.

enter image description here

Upvotes: 1

Related Questions