Determining the multiline language level of a text language

I am trying to create a new syntax definition for Sublime Text. I designed a regex to highlight the match on each line, but I would like the match to include newlines as well as any character. Here's a regex from a tmLanguage file, working within a single line:

<key>match</key>
<string>\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}</string>

      

I tried to change the dot match (.) For multiline spacing, but it doesn't actually display the entire block. I understand what the modifier is? M: should work, but doesn't.

<key>match</key>
<string>(?m:(\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}))</string>

      

Is there a way to declare a language definition regex that will match multiple lines?

+3


source to share


1 answer


Use a one-line modifier instead:

<key>match</key>
<string>(?s:(\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}))</string>

      



You are misunderstanding the modifier (?m)

. Your regex is always applied on one line.

  • Using a multi-line modifier means that your regex will treat your text as multiple lines (this is the default behavior) and then add ^(...)$

    around each line.
  • Using a one-line modifier ^(...)$

    won't be added and then .

    match\r\n

+4


source







All Articles