Sublime Forum

Regex lookbehind not working in .tmLanguage?

#1

Hello, I’m trying to add an entry to my custom language file, and for some reason regex lookbehind does not work. I keep getting the error “Error parsing plist xml: Error reading end tag.”

This error arises when I add the string

\b((?<=x)[0-9a-fA-F]+)

I also tried without the \b() surrounding the expression, but still get the same error. I assume I must be making an error, but I can’t figure out what it is after searching around for quite some time.

Longer excerpt (the first entry with lookahead works fine)

<dict> <key>match</key> <string>\b(0x(?=[0-9a-fA-F]+))</string> <key>name</key> <string>constant.numeric.hexadecimal.start</string> </dict> <dict> <key>match</key> <string>\b((?<=x)[0-9a-fA-F]+)</string> <key>name</key> <string>constant.numeric.hexadecimal.finish</string> </dict>

0 Likes

#2

Well, I notice lookbehind is not used in any of the packaged .tmLanguage files included with ST2, so perhaps it’s just not supported then? Seems a bit weird, but haven’t been able to find any other similar problems (or solutions) posted around the net.

0 Likes

#3

Remember you’re editing an XML document, where “<” is spelled “<” in content.

0 Likes

#4

I was just editing one of these things (in Sublime Text 3)… was doing a lookahead and wanted to match an equals sign before the rest of my regex… had to do this: (?&lt;==) because less-than is spelled ampersand L T semicolon in XML (thx frou). The ‘<’ makes it a lookahead instead of a lookbehind.

0 Likes