开发者

Looking for Regex

I want to validate Winforms text box with regex.

The input sting example:

ZX1 OR N?V OR 2L? OR ?55 (any sequence of three symbols length strings with OR betwee开发者_运维问答n them)

What is the regex that you would advise?

UPDATE: Trying this one but seams to be it is not 100% correct

string text = "ZX1 OR N?V OR 2L? OR ?55";
Regex r = new Regex("([0-9A-Z?]{3} OR )*[0-9A-Z?]{3}");


"^\\s*\\S{3}(?:\\s+OR\\s+\\S{3})*\\s*$"

should work in a variety of languages.

\\S

matches any non-space character, and

\\s

matches any space character, so the regex above matches any number of triplets of non-space characters separated by the string "OR" surrounded by space characters.

The ^ and $ serve to ensure that it matches the whole string so you can take those out if you want to find this pattern inside a larger string.


What is the list of possible symbols you can have? can you have at most one question mark? This will match what you've given, but it will also match multiple question marks.

([A-Z?]{3} OR )*[A-Z?]{3}


try...

(([\w\S]{3}\s+)or\s+)+[\w\S]{3}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜