Sameer
Sameer

Reputation: 548

RegEx c#: regex expression that does not contain substring but ends with _Number

I wanted to find string that does not contains substrings (test,Test, back, Back, Down, down) and ends with _number e.g.

test_02.txt -- False
Final_test_02.txt -- False
final_02.txt -- True
final_3.txt -- True
final_17.txt -- True
Down-05.txt -- False

How to do this efficiently with Regular Expression. I am new to RegEx. I have tried

((.*)^(test|Test|back|Back|Down)(.*)_\d)

But it is not working.

Upvotes: 0

Views: 56

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174706

Seems like you want something like this,

^(?!.*?(?:[Tt]est|[Bb]ack|[Dd]own)).*?_\d+\.[^.\n]+$

Use negative lookahead assertion to match the strings which won't contain a particular substring.

DEMO

Upvotes: 2

Related Questions