2

I want regular expression for time word and []{}^ those string format not allowed in string.

Like,

testtime -> allowed
tim etest -> allowed
thetimetest -> allowed
the time test -> not allowed
test[my -> not allowed
my}test -> not allowed
test^time -> not allowed

I develop below regular expression for word not allowed in string. But they cant check with case sensitive in c#.

   ^((?!Time)[^[\]{}])*$
Jeet Bhatt
  • 724
  • 7
  • 21

3 Answers3

1

Try this:

^((?!time)[^.])*$

Though a couple String.contains combined with Boolean logic might be clearer and more performant.

Paul Draper
  • 71,663
  • 43
  • 186
  • 262
  • Hello, I edited my question, please check with this. – Jeet Bhatt Dec 30 '13 at 06:17
  • @JeetBhatt, I am not sure what you wanted. This is case-sensitive. If you want case-insensitive, put `(?i)` at the beginning of the regex, per http://stackoverflow.com/questions/2439965/case-insensitive-regex-without-using-regexoptions-enumeration. – Paul Draper Dec 30 '13 at 06:38
  • i used this, but still they not work in asp.net regular expression validation control. – Jeet Bhatt Dec 30 '13 at 06:57
1

Assuming you want a string that doesn't contain time or ...The regex would be

^(?!.*time)(?!.*[.]).*$
Anirudha
  • 31,626
  • 7
  • 66
  • 85
1

You can use a negative lookahead like this:

^(?!.*time)[^.]*$

regex101 demo


EDIT: As per update, you can use this regex:

^(?!.*\btime\b)[^.^\[\]{}]*$

regex101 demo

As for case insensitivity, you can either use the flag RegexOptions.IgnoreCase or use (?i) in the regex as like such (?i)^(?!.*\btime\b)[^.^\[\]{}]*$

Jerry
  • 68,613
  • 12
  • 97
  • 138