c# - Regular expression with a limited length, spaces and other limitations -
i'm looking following regex:
- the match can empty.
- if not empty, must contain @ least 2 characters english letters or digits.
- the regex must allow spaces between words.
this come with:
^[a-za-z0-9]{2,}$
it works fine, not except spaces between words.
here, can use regex make sure match kind of spaces (even hard space), , make sure allow empty string match:
(?i)^(?:[a-z0-9]{2}[a-z0-9\p{zs}]*|)$
c#:
var rg11x = new regex(@"(?i)^(?:[a-z0-9]{2}[a-z0-9\p{zs}]*|)$"); var tst = rg11x.ismatch(""); // true var tst1 = rg11x.match("mc donalds").value; // mc donalds
Comments
Post a Comment