user2238884
user2238884

Reputation: 602

A regex that may contain a palticular pattern but not another pattern

Consider the below lines:

  1. यदि रेनेसाँ मिथ्या है तो इतिहास क्या है? जब हम इसके स्वाभाविक तत्वों को देखें <FIL\>

  2. यदि रेनेसाँ मिथ्या है तो इतिहास क्या है? जब हम इसके स्वाभाविक तत्वों को देखें LIF

  3. यदि रेनेसाँ मिथ्या है तो इतिहास क्या है? जब हम इसके स्वाभाविक तत्वों को देखें

I want to write a regex that removes lines which a) do not contain Devanagari characters b) except some exact tags ( like, <FIL\> ). So basically, it should not match line 1. and 3. but only line 2.

I tried merging a capturing group inside a negated set [^ँ-ॿ(FIL)] but apparently that doesn't work. I tried other combinations of such kind but couldn't reach the solution.

Upvotes: 0

Views: 70

Answers (1)

anubhava
anubhava

Reputation: 786011

In C# you can use this regex:

^(?!.*?<FIL\\>)(?=.*?[^\p{IsDevanagari}\p{P}\s]).+$

RegEx Demo

Upvotes: 2

Related Questions