开发者

How to match '{{{' using RegEx

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜