KjetilJar
KjetilJar

Reputation: 55

Counting characters in a line in notepad++

I'm trying to count the amount of times a character in a single line appears to then edit the lines which it does.

Say i have a line that goes:

\serv\file\subfile\subsubfile\subsubsubfile

Is there any way I can count the amount of times the \ character appears, and if it doesn't appear more than say twice, clear the line and leave it blank?

Upvotes: 4

Views: 17905

Answers (3)

The Guy with The Hat
The Guy with The Hat

Reputation: 11132

Try this regex:

^[^\\]*\\[^\\](?:*\\[^\\]*)?$

Replace with nothing. Explanation and demonstration here: http://regex101.com/r/qW0jE3

If you want to change the number of \s allowed, you have three options:

  • Change the number of (?:*\\[^\\]*) in the above regex.
  • Change the second number in this regex: ^(?:[^\\]*\\[^\\]*){0,2}$.
  • Change the first number in this regex: ^(?:\\?[^\\]*){2}$.

Upvotes: 1

Kent
Kent

Reputation: 195259

find ^([^\\]*[\\]?[^\\]*){0,2}$

replace with empty string

Upvotes: 4

Pankaj Jaju
Pankaj Jaju

Reputation: 5481

Is this something that you want to do?

Find - ^(?!.*\\.*\\.*\\.*).*$\r\n

Replace -

enter image description here

When you do Replace All, you would also get the number of lines that were replaced - giving you the count

In my example, the 2nd, 4th, and 5th lines would be deleted because they have less than 2 slashes ()

Upvotes: 2

Related Questions