How can filter variations of the word 'the' using a regex in C#?
I am completely new to writing regular expressions. I am trying to write a Regex that will not allow the following terms 开发者_运维问答in a text box.
the The T h e
If you want to match on things like 'WHAT H ELL' then simply rip all the whitespace from the string so you get 'WHATHELL' and then look for 'THE'
If you don't include those situations, then use this regex with case sensitivity turned off
\bt\s*h\s*e\b
result
WHAT H E - fail
The - success
T he - success
th E - success
t h e - success
the - success
them - fail
hasthem - fail
has them - fail
/t ?h ?e/i
will match any of the variations above (and others such as T hE).
How you reject input that matches this pattern depends on the language and libraries you are using.
I recommend using http://www.regular-expressions.info they have a very good quickstart guide and a very through tutorial. It helped me a lot when I first was learning Regular expressions.
It depends what language you are using, but you can specify case-insensitivity.
if you want a regex that checks to see if it exists try:
(the|t\sh\se)
精彩评论