1

The given string is something like:

words words {{{value}}} some other words {{{value2}}}

I'm trying the following one:

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

1gn1ter
  • 1,414
  • 2
  • 22
  • 47
  • David already answered your question, I explained in my answer here [how-exactly-do-regular-expression-word-boundaries-work-in-php](http://stackoverflow.com/questions/6531724/how-exactly-do-regular-expression-word-boundaries-work-in-php/6531959#6531959) the word boundaries a bit more in detail . You can ignore that this question has a php tag, this doesn't make a difference for understanding word boundaries. – stema Sep 08 '11 at 13:23

2 Answers2

5

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+)}}}"
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 1
    The curly braces don't need to be escaped. If they are not part of a quantifier like `{1,2}` they are matched literally. Anyway +1 – stema Sep 08 '11 at 13:15
2

Remove the \b, it means word-boundary but there're none between space and { in the given string.

Toto
  • 89,455
  • 62
  • 89
  • 125