How do I put a regular expression to check if a string starts with certain pattern and is NOT ending with certain pattern.
Example:
Must StartsWith: "US.INR.USD.CONV"
Should not end with: ".VALUE"
Passes Regex: "US.INR.USD.CONV.ABC.DEF.FACTOR"
Fails Regex Check: "US.INR.USD.CONV.ABC.DEF.VALUE"
I am using C#.
You can use this regex based on negative lookahead:
^US\.INR\.USD\.CONV(?!.*?\.VALUE$).*$
^US\.INR\.USD\.CONV
- Match US.INR.USD.CONV
at start of input(?!.*?\.VALUE$)
- Negative lookahead to make sure line is not ending with .value
^US\.INR\.USD\.CONV.*(?<!\.VALUE)$
Try this.See demo.
https://regex101.com/r/fA6wE2/26
Just use a negative lookbehind to make .VALUE
is not before $
or end of string.
(?<!\.VALUE)$ ==>Makes sure regex engine looks behind and checks if `.VALUE` is not there when it reaches the end of string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With