Regular expression to extract all words starting with colon

regex

Solution

For being able to handle such an easy case by yourself you should have a look at regex quickstart.

For the meantime use:

:\w+

Problem

I would like to use a regular expression to extract "bind variable" parameters from a string that contains a SQL statement. In Oracle, the parameters are prefixed with a colon. For example, like this: ``` SELECT * FROM employee WHERE name = :variable1 OR empno = :variable2 ``` Can I use a regular expression to extract "variable1" and "variable2" from the string? That is, get all words that start with colon and end with space, comma, or the end of the string. (I don't care if I get the same name multiple times if the same variable has been used several times in the SQL statement; I can sort that out later.)

Original source