Thursday 2 January 2020

Regex - Does not contain certain Characters



I need a regex to match if anywhere in a sentence there is NOT either < or >.



If either < or > are in the string then it must return false.



I had a partial success with this but only if my < > are at the beginning or end:




(?!<|>).*$


I am using .Net if that makes a difference.



Thanks for the help.


Answer



^[^<>]+$



The caret in the character class ([^) means match anything but, so this means, beginning of string, then one or more of anything except < and >, then the end of the string.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...