Reputation:
I want to detect lines which :
OR
OR
I try to detect which is as above. But my problem that it's detect two groups for lines :
BLOC3_ETAPE1=
U36_B1=
You find my test here : https://regex101.com/r/DFHmce/1
^(-.*|.*[<>=](?:(\s*)|(?:(?!\s*$).+[(](?:.*)[,](?:.*)[)](?:.*)))|(?:.*SN.*))$
Expected Lines Result in the same group:
TEST APPARTEMENT
S1=32.319156K(0.5M,37.5K)R
S4<9.782835K(9.5K,10.5K)R
S5>9.782835K(2.5K,10.5K)R
U36_B1=
U6%=SN54LS02J
BLOC3_ETAPE1=
U9%=SN54LS273J TestPos
Upvotes: 0
Views: 31
Reputation: 163632
You could use an alternation with 4 parts.
^(?:-.*|.*?SN.*|[^\r\n=<>]*[=<>].*?\([^,\r\n]+,[^,\r\n]+\)|[^\r\n_]+_[^\r\n_]+=$).*
The 4 parts will match:
^
Start of string(?:
Non capture group with 4 alternatives
-.*
Match -
and the rest of the line|
Or.*?SN.*
Match a line that contains SN|
Or[^\r\n=<>]*[=<>]
Match until any of <
=
or >
.*?
Match any char except a newline as least as possible\([^,\r\n]+,[^,\r\n]+\)
Match (
1+ chars except a comma or newline. Match the ,
and again 1+ chars except a comma or newline and the closing )
|
Or[^\r\n_]+_[^\r\n_]+=$
Match a part with an underscore ending on =
)
Close group.*
Match the rest of the lineSee the regex demo
Upvotes: 1