本文介绍了如何使用RegEx匹配'{{{'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定的字符串类似于:
words words {{{value}}} some other words {{{value2}}}
我正在尝试以下操作:
const string pattern = @"\b({{{)\w+(}}})\b";
Regex optionRegex = new Regex(pattern, RegexOptions.Compiled);
MatchCollection matches = optionRegex.Matches(text);
和 @"\ b(\ {\ {\ {)\ w +(\} \} \})\ b"
没有帮助.请帮助创建正则表达式TIA
and @"\b(\{\{\{)\w+(\}\}\})\b"
didn't helped. Please, help to create regex, TIA
推荐答案
您的正则表达式应为:
@"{{{\w+}}}"
问题在于,您尝试匹配的位置没有单词边界( \ b
).
The problem is that there is no word boundary (\b
) where you were trying to match.
您可以根据需要添加分组,但是您似乎不太可能这样做,因为您知道第一组包含 {{{/code>.也许您打算将单词分组在里面:
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+)}}}"
这篇关于如何使用RegEx匹配'{{{'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!