How to find words in a string that start with @ in C#

1 Answer

0 votes
using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main() {
        string s = "c @php @csharp java @cpp python cobol @swift";  

        string pattern = @"\B@\w+";
        MatchCollection mc = Regex.Matches(s, pattern);
        
        foreach (Match match in mc) {
            Console.WriteLine(match);
        }
    }
}




/*
run:

@php
@csharp
@cpp
@swift

*/

 



answered Feb 27, 2021 by avibootz
...