I'm editing a TextMate grammar for SQL. It currently has the regex (keywords omitted for clarify):
(?i:^\s*(create)\s+(aggregate|function|(unique\s+)?index|table)\s+)(['"`]?)(\w+)\4
This correctly matches a function definition like
CREATE FUNCTION similarity
I wanted to handle CREATE OR REPLACE
, so I changed the regex to
(?i:^\s*(create(\s+or\s+replace)?)\s+(aggregate|function|(unique\s+)?index|table)\s+)(['"`]?)(\w+)\4
and it wouldn't match a CREATE
or a CREATE OR REPLACE
. I fixed it by making the new optional group passive as well:
(?i:^\s*(create(?i:\s+or\s+replace)?)\s+(aggregate|function|(unique\s+)?index|table)\s+)(['"`]?)(\w+)\4
But.. why didn't it match before? I would expect it to match, but then to possibly give me a capture group I wasn't expecting (if the outer passive-group indicator doesn't trickle down to the new inner group).