Regex to match word beginning with @

前端 未结 4 1109
长情又很酷
长情又很酷 2021-01-13 22:21

I am trying to develop some regex to find all words that start with an @:

I thought that \\@\\w+ would do it but this also matches words that have @ con

4条回答
  •  无人共我
    2021-01-13 22:43

    And what about a non-Regex approach?

    C# version:

    string input = "word1 word2 @word3 ";
    string[] resultWords = input.Split(' ').ToList().Where(x => x.Trim().StartsWith("@")).ToArray();
    

    VB.NET version:

    Dim input As String = "word1 word2 @word3 "
    Dim resultWords() As String = input.Split(" "c).ToList().Where(Function(x) x.Trim().StartsWith("@")).ToArray
    

提交回复
热议问题