Like this:
var reg = new Regex(@"%!(?<word>\w+)!%");
var inStr = @"You don't want no %!beef!%, boy
Know I run the streets, boy
Better follow me towards
Downtown
What you see is what you get %!girl!%
Don't ever forget girl
Ain't seen nothing yet until you're
%!Downtown!%";
var results = reg.Matches(inStr).Cast<Match>().Select(m => m.Groups["word"].Value);
This will give you a list of matched words. Converting it to a comma-separated string is an exercise I’ll leave up to you..
Also, next time you should probably do some quick research, you’re eventually going to have to learn simple regexes..
3
solved C# Extract Words Beginning with %! and Ending With !% [closed]