I have a specific format data as shown below in notepad , i would like to remove lines having textual data like "This is first sentence".
1.(AB123456)
2.This is first sentence
3.(AD2341278)
4.tHIS is second sentence
5.(ABCD1234)
6.4 (four) is a number
One hint is all the lines that i need have a bracket "(" , however in textual data there are brackets too.
I tried using other means like number of letters (5 or more letters, since there are maximum 4 letters even in one i need to retain)like in regex (.*[A-Za-z]){5,}
, however it did not help me to delete the entire line.
Can anyone help me with simple regex solution to remove lines?
Desired output should look like this
CodePudding user response:
Case 1: Matching lines like (AB123456)
You can try chaining your match to spaces end of line character [\s]*($|\n)
and retrieve all alphanumeric characters between parentheses \([\w] \)
.
\([\w] \)[\s]*($|\n)
Case 2: Matching lines like This is first sentence
You can try chaining your match to the start of line character (\n|^)
, catch the first character as a non opened parenthesis '[^(]', then match everything else on the same line .*
.
(^|\n)[^\(].*