Reputation: 55
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
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:
(?:*\\[^\\]*)
in the above regex.^(?:[^\\]*\\[^\\]*){0,2}$
.^(?:\\?[^\\]*){2}$
.Upvotes: 1
Reputation: 5481
Is this something that you want to do?
Find - ^(?!.*\\.*\\.*\\.*).*$\r\n
Replace -
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