Sublime Text: Why regex in syntax highlighting does not work?

2

1

In Sublime Text 3, a default syntax highlighting rule paints a SQL SELECT just fine if it's in the same line, but not if it's in the next line:

single-line sql string vs multiline sql string

After reading this question I opened the PHP package (this is a php project) and looked at the syntax rules (PHP.tmLanguage):

<dict>
    <key>begin</key>
    <string>"\s*(?=(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER)\b)</string>
    <key>beginCaptures</key>
    <dict>
        <key>0</key>
        <dict>
            <key>name</key>
            <string>punctuation.definition.string.begin.php</string>
        </dict>
    </dict>

As far as I could tell that regex is correct, but I still tested it in regex101. It does capture the SELECT just fine there, so I don't think there is any problem with the actual regex.

Any idea how to make the syntax highlighted on multiple line SQL strings?

Purefan

Posted 2015-07-13T12:35:20.920

Reputation: 311

My best guess: \s isn't selecting newlines, and [\s\r\n] needs to specified. Alternatively, there's some override on newlines elsewhere. I'm not super familiar with Sublime Text, but hopefully this is a bit helpful. – Graham – 2018-05-04T02:38:37.147

Okay, I just installed Sublime Text and looked at the syntax highlighting for the PHP example you provided, and it highlighted the SELECT whether or not there was an indent after the opening quotation mark. I also don't know where you got the PHP.tmLanguage; I looked at the syntax in PHP.sublime-package, and don't currently have a file called PHP.tmLanguage on my computer. – Graham – 2018-05-04T22:33:56.100

@Graham My initial problem was not with an indent, but with a line break. Also, I asked that question on July 13th 2015, I guess quite a lot has changed in Sublime in the last 3 years. But please feel free to try with a line break, not an indent. Disclaimer: I dont use Sublime anymore – Purefan – 2018-05-05T11:32:47.117

Sorry, I didn't look at the asking date carefully. Whoops. I also meant line break instead of indent. – Graham – 2018-05-06T12:51:56.787

No answers