简体   繁体   中英

Looking for Regex

I want to validate Winforms text box with regex.

The input sting example:

ZX1 OR N?V OR 2L? OR ?55 ZX1 OR N?V OR 2L? OR ?55 (any sequence of three symbols length strings with OR between 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}

尝试...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM