Shayan Es
Shayan Es

Reputation: 23

Regex to delete lines containing exact number of semicolons, Notepad++

Example:

a ; user ; name ; pass ; 123 ;
b ; login ; name ; password ; def;
c ; 
d ;
e ; email ; [email protected] ; pass ; 789 ;

lines 1,2,5 have 5 semicolons and lines 3,4 have 1 semicolon I want line 3 and 4 deleted.

result:

a ; user ; name ; pass ; 123 ;
b ; login ; name ; password ; def;
e ; email ; [email protected] ; pass ; 789 ;

Upvotes: 2

Views: 140

Answers (2)

M A
M A

Reputation: 72874

Use the following pattern in the regex matching the line to be replaced:

^[^;]*;[^;]*$

[^;] matches any character except the semi-colon.

The characters ^ and $ at the beginning and the end mark the start and the end of the line respectively.

Here is a demo

Upvotes: 1

anubhava
anubhava

Reputation: 785611

You can use this regex for deletion:

^[^;]*; *$

RegEx Demo

Upvotes: 1

Related Questions