I want to find all alphanumeric characters between {{ and }} in a text.
Eg. if the text contain the substring {{foo}} I want to find foo.
If it contains {{#foo}} I want to find foo not #foo.
I have tried the following pattern (?<=\\{\\{)(.*?)(?=\\}\\}), but it always returns # in the second example above.
Can anyone help me?
You can try this:
This expression lets you skip non-alphanumeric characters after
{{and before the first alphanumeric character, if any. It also lets you have non-alphanumerics preceding the closing}}.EDIT
In response to your comment about
f#oo: as far as I know, you cannot “glue together” multiple non-contiguous matched groups. The easiest solution is to use another regexp in your C# hosting program:You would need to go back to your original regexp, because the one from the answer matches only the first contiguous block of alphanumerics.