Regex for only Select queries? -


i looking regex allows select queries strictly, no inserts, deletes, alters or of sort can allowed , query can have multiple lines..

i tried

var pattern="(^select)^((?!insert|delete|alter).)*$";  var pattern=^(?!insert|delete|alter|modify|add|create|drop|truncate|rename|update|rollback|commit|grant|revoke|savepoint)(.(?!insert|delete|alter|modify|add|create|drop|truncate|rename|update|rollback|commit|grant|revoke|savepoint))*$";   

how make not match insert or keywords on multiple lines (in javascript).

it fails in

eg: select * insert  

which means should start "select" , cannot have insert anywhere in query doesn`t work.

there lot of problems idea, mentioned in comments. far how accomplish this:

/^select(?:(?!insert|delete|alter)[\s\s])*$/i 

this make sure select (case-insensitively) first word. used rest of expression exactly. threw * repetition non-capture group, , updated . [\s\s] (because . matches character except newline).


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -