C# Find a matching string by regex

后端 未结 5 1782
有刺的猬
有刺的猬 2020-12-07 06:02

I want to find out, whether my string contains a text like #1, #a, #abc, #123, #abc123dsds and so on... (\'#\' character with one or more characters (digits and letters).

5条回答
  •  离开以前
    2020-12-07 06:14

    Or without regex, you can use a combination of StartsWith, Enumerable.Any and char.IsLetterOrDigit methods like;

    var s = "#abc123dsds+";
    var matches = s.Length > 1 && s.StartsWith("#") && s.Substring(1).All(char.IsLetterOrDigit);
    

提交回复
热议问题