开发者

How to match '{{{' using RegEx

开发者 https://www.devze.com 2023-04-03 07:35 出处:网络
The given string is something like: words words {{{value}}} some other words {{{value2}}} I\'m trying the following one:

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

精彩评论

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