2

Example:

a ; user ; name ; pass ; 123 ;
b ; login ; name ; password ; def;
c ; 
d ;
e ; email ; s@d.com ; 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 ; s@d.com ; pass ; 789 ;
Shayan Es
  • 23
  • 2
  • 1
    Have you tried putting regex together yet? When I try to work out a regex solution, I always pop it into https://regex101.com/ until I figure it out – Chris Jan 05 '15 at 17:47
  • Very similar question to http://stackoverflow.com/questions/863125/regular-expression-to-count-number-of-commas-in-a-string – titaniumdecoy Jan 05 '15 at 17:52

2 Answers2

1

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

Jeremy W
  • 1,889
  • 6
  • 29
  • 37
M A
  • 71,713
  • 13
  • 134
  • 174
1

You can use this regex for deletion:

^[^;]*; *$

RegEx Demo

anubhava
  • 761,203
  • 64
  • 569
  • 643