Find all words starts with @@ and ends with @@ in long string

.net, c#, regex, string

Solution

Try this regex:

@@\b\S+?\b@@

Sample Code:

List<string> lst = new List<string>();
MatchCollection mcol = Regex.Matches(sampleString,@"@@\b\S+?\b@@");

foreach(Match m in mcol)
{
    lst.Add(m.Tostring());
}

Here `lst` contains matched value(s), compare each value and replace it as per you criteria.

Sample live demo

Problem

I have a quite big string. In that big string, I want to get all UNIQUE words starts with @@ and ends with @@. Between @@ could be text, number or alphanumeric or anything. Once I get all the UNIQUE words starting @@ and ends with @@, I want to replace each word with a value which matches a key in a different array. Looking for the solution in C#.

Original source