The given string is something like:
words words {{{value}}} some other words {{{value2}}}
I'm trying the following one:
开发者_Python百科const string pattern = @"\b({{{)\w+(}}})\b";
Regex optionRegex = new Regex(pattern, RegexOptions.Compiled);
MatchCollection matches = optionRegex.Matches(text);
and @"\b(\{\{\{)\w+(\}\}\})\b"
didn't helped. Please, help to create regex, TIA
Your regex should be:
@"{{{\w+}}}"
The problem is that there is no word boundary (\b
) where you were trying to match.
You can add the grouping in if you need it, but it seems unlikely that you do since you know that the first group contains {{{
and the second contains }}}
. Perhaps you meant to group the word inside:
@"{{{(\w+)}}}"
Remove the \b
, it means word-boundary but there're none between space and { in the given string.
精彩评论