So I am trying to figure out a Regular Expression and am having some issues. What I want to find (match) is all of the SQL parameters in a large script file, but NOT match items in single quotes (such as email addresses). For example:
INSERT INTO [User]
(
[UserGuid], [CompanyGuid], [Name], [EmailAddress]
) VALUES (
@UserGuid1, @CompanyGuid, 'Jason', '[email protected]'
)
With @UserGuid1
and @CompanyGuid
matching, but not @jason matching. I have been using this RegEx:
(@+[\w]+)
But it matches the email address, so I tried to do a negative look ahead/behind like this:
(?<!')[\W](@+[\w]+)[\W](?!')
but it is matching the '(' in the following example:
INSERT INTO [User] ([UserGuid]) VALUES (@UserGuid1)
Anyone have an idea what I am missing here? Something that can say: "anything that is NOT in a quote set?". Also, it is safe to assume balanced quote sets.