I have an sql query. I want to allow user to modify only relational operators or values within single quotes
My input string is.
Select * from defect where Quantity < '9' and Date <= curdate() and Date >=
date_sub(curdate(), interval '3' month)
I am trying following patterns to match the above string as it is. I also tried ^ at beginning and $ at end. But no positive result in any case
1. Select * from defect where Quantity [<|(>)|(=)|(<=)|(>=)|(like)] '.*' and
Date [<|(>)|(=)|(<=)|(>=)|(!=)|(like)] curdate() and Date [<|(>)|(=)|(<=)|(>=)
|(!=)|(like)] date_sub(curdate(), interval '.*' month)
2. Select * from defect where Quantity (<|(>)|(=)|(<=)|(>=)|(like)) '.*' and
Date (<|(>)|(=)|(<=)|(>=)|(!=)|(like)) curdate() and Date (<|(>)|(=)|(<=)|(>=)
|(!=)|(like)) date_sub(curdate(), interval '.*' month)
Update Need guidance why my patterns are not matching my input string. What could be the mistake?
There are more problems: You’re using square brackets incorrectly:
means “one character out of the following:
<>()|=eikl“.Use parentheses instead of brackets, and group sensibly:
Also, you should be more specific: Use
'[^']*'instead of'.*'.Finally, if you want to match a literal parenthesis, you need to escape it in your regex: