Regex pattern UNMATCH in VB.NET or C#
need a pattern to match a string which should NOT be --
777777777
888888888
999999999
or start with 00
or 02
or 04
.
when i tried to go开发者_Python百科 create a pattern to match the above requirements, i got it done by -
Dim _pattern6 As String = "^(7+|8+|9+|(00|07|08|09|17|18|19|28|29|43|48|69|70|78|79|80|96|97).*)$"
could not get the NOT MATCH part done.
What you want is negative lookahead.
@"^(?!([789])\1{8}$|0[024]).*$"
The negative lookahead (?!...)
means "whatever follows this position cannot match any of these patterns." So (?!7{9}).*
means "any string of characters (.*
) that doesn't start with nine 7
s in a row." The ([789])\1{8}$
is shorthand for 9 repeated digits. It means "Either 7, 8, or 9 followed by itself another 8 times."
Tested on RegexPlanet: http://fiddle.re/tz8p
You could try to match to unwanted parts. If that returns true, you know the attempt to "not match" would have been false, and vice versa.
Here you go
[^(7{9}|8{9}|9{9}|00|02|04)]+
精彩评论