0

I am trying to write a custom syntax definition for SublimeText 2. I made the regex and tested it (using SublimeText2's regex find), and the regex works for what i want it to, however, once I put it into the .tmLanguage file I get the following error:

Error in regex: undefined group option in regex

Here is the regex:

\b([Aa]|[Tt]he|[Aa]n)\b(?(?![ (),'.a-zA-Z]*\b([Aa]|[Tt]he|[Aa]n)\b)([ (),a-zA-Z]*[0-9]{2,3})|(,,,))

And here is my XML .tmLanguage file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>fileTypes</key>
    <array>
        <string>techpaper</string>
    </array>
    <key>name</key>
    <string>Tech Paper</string>
    <key>patterns</key>
    <array>
        <dict>
            <key>match</key>
            <string>\b([Aa]|[Tt]he|[Aa]n)\b(?(?![ (),'.a-zA-Z]*\b([Aa]|[Tt]he|[Aa]n)\b)([ (),a-zA-Z]*[0-9]{2,3})|(,,,))</string>
            <key>name</key>
            <string>string.list.element</string>
        </dict>
    </array>
    <key>scopeName</key>
    <string>source.techPaper</string>
    <key>uuid</key>
    <string>092f2f93-b3ad-461d-9ca2-978b1c2bb7ad</string>
</dict>
</plist>

Thanks in advance for your help!

matthewjselby
  • 112
  • 2
  • 8

1 Answers1

0

The W3C XML flavor of regex is very lacking in advanced operation, and does not support conditionals or lookaround, which I suspect may be what it refers to as an undefined group option.

The following part is a negative lookahead, which is not allowed on it's own either:

(?![ (),'.a-zA-Z]*\b([Aa]|[Tt]he|[Aa]n)\b)

You are also using that negative lookahead with (?( .. )()|(), which I suspect is used to create a conditional statement which is not supported by XML flavor regex either.

melwil
  • 2,547
  • 1
  • 19
  • 34