Combining these two Regular Expressions into one

前端 未结 6 1697
眼角桃花
眼角桃花 2020-12-16 17:38

I have the following in C#:

public static bool IsAlphaAndNumeric(string s)
{
    return Regex.IsMatch(s, @\"[a-zA-Z]+\") 
        && Regex.IsMatch(s,         


        
6条回答
  •  执笔经年
    2020-12-16 18:04

    You could use [a-zA-Z].*[0-9]|[0-9].*[a-zA-Z], but I'd only recommend it if the system you were using only accepted a single regex. I can't imagine this would be more efficient than two simple patterns without alternation.

提交回复
热议问题