I'm having trouble getting list of all parameters in SQL query using Regex.
Example of the query:
SELECT ... WHERE col1 = :user AND col2 = 'HELLO' OR col3 = :language
To obtain parameters, I use following regex pattern:
Pattern.compile(":([\\w.$]+|\"[^\"]+\"|'[^']+')", Pattern.MULTILINE)
The pattern returns list of parameters correctly:
:user
:language
The problem is with another type of query, where literals might contain character ':'
WHERE col1 = :user AND some_date > '2022-09-26T10:22:55'
The list of parameters for this case is:
:user
:22
:55
Is there any better approach that will not consider contents of literals as parameters?
Pattern.compile("[^'\":]*:([\\w.$]+|\"[^\"]+\"|'[^']+')", Pattern.MULTILINE)code <> '*'\nAND code IN (select x from ... where user = :user)it considers\nAND code IN (select x from ... where user = :userto be parameter.Pattern.DOT_ALLwill let the.also match newlines. Forgotten