java - Regex to extract query parameters fails with DateTime Strings -


suppose folowing sql command:

update [table] set [value] = 'username' key1 = :param1 , key2 = :param2 

i extract :param1 , :param2 sql. so, i´m using following regex match sql string:

:([\w.$]+|"[^"]+"|'[^']+') 

this working fine, except when sql string contains colon (:) between quotes (") or single quotes (').

eg, regex matcher returns me :param1 , :param2 following queries well:

 update [table] set [value] = ':username' key1 = :param1 , key2 = :param2  update [table] set [value] = 'user=:username' key1 = :param1 , key2 = :param2  update [table] set [value] = '2015-04-26 21:59:24' key1 = :param1 , key2 = :param2 

because values :username, user=:username , 2015-04-26 21:59:24 between single quotes...

i tried modify regex expression, nothing seems work. should do?

/'.*?'|(:[^\b]+?\b)/g 

your results in group #1 (the paren match).

demo of regex.

edit: per weirdness discussed below: /'.*?'|(:\b+?\b)/g


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -