2
votes

Example String:

{{--
    some text
--}}

I'm trying to match anything between and including {{-- up to and including the first --}} It would need to capture returns and line breaks as well.

I tried something like this: \{\{--[^\r\n]--\}\} which seems to capture everything between the brackets but I can't quite figure out how to capture the brackets as well.

edit I'm trying to modify a sublime text plugin that adds syntax hilighting for laravel's blade templating. As mentioned below: '({{--[\s\S]*--}})' matches what I'm looking to match. The brackets are probably being overridden by different rules.

1
Your example matches the brackets too (the brackets are listed in the regex). What environment are you doing this in (what's your regex engine and interface)? Your example is good except that it won't allow line breaks. I can help you fix that if I know more about your environment and why you think your example doesn't capture the brackets.TypeIA
Hmm. Honestly I don't know. Basically I was looking at a plugin for Sublime Text 2 that adds syntax hilighting to Laravel's blade templating. The comments for it don't include new lines so I was trying to fix it and then ran into this issue. The original that works for the first line only is: \{\{--(?=(|\s*|))(.+|)(?=(|--\}\}|)) if that helps at all.gin93r

1 Answers

2
votes

You can use this regex:

(\{\{--[\s\S]*--\}\})

Online Demo: http://regex101.com/r/mT1jT4

Explanation:

1st Capturing group (\{\{--[\s\S]*--\}\})
\{ matches the character { literally
\{ matches the character { literally
-- matches the characters -- literally
[\s\S]* match a single character present in the list below
Quantifier: Between zero and unlimited times, as many times as possible,
            giving back as needed [greedy]
\s match any white space character [\r\n\t\f ]
\S match any non-white space character [^\r\n\t\f ]
-- matches the characters -- literally
\} matches the character } literally
\} matches the character } literally