Home > Back-end >  How to match only that phrase which ends on ";" and has one pair of brackets?
How to match only that phrase which ends on ";" and has one pair of brackets?

Time:11-18

I have somethink like that:

RuleFor(x =>x.xd != null).NotEmpty(); // I dont want to match this

RuleFor(x =>x.xd != null);            // I want to match only this, independently of that, what is in brackets

CodePudding user response:

Try:

^(?!.*\(.*\).*\(.*\)).*;$

Regex demo.


  • (?!.*\(.*\).*\(.*\)) - don't match string where two (.*) are found
  • .*;$ - match all where the last character is ;
  • Related