I have some text that I want to match and replace in C#
The text will be something like this and can occur multiple times in a string
This is some content with a !!Some link text here this can be anything::/something/something/url.html!! inside it
I’m currently using this regex and replace but it’s not working. It only seems to work if there are no spaces in the values.
Regex r = new Regex("!!(?<first>\\S+)::(?<last>\\S+)!!");
content = r.Replace(content, delegate(Match match) { return ReturnCustomSpan(match.Groups[1].Value, match.Groups[2].Value); });
Can anyone help please? I’m a regex noob and I can’t figure this one out.
\S is all non-whitespace characters, so you’re explicitly excluding spaces. If you want to match any characters, use .+ instead of \S+