Apologies, if this is duplicate. I am matching a sql string using regex in java. In my query i may or may not have where clause.
I am using following regex
\bselect\b\s(.*)\s\bfrom\b\s(.+)\s(?:where)?\s(?:(.*))
which is working fine for
select a,b from tab1 where a=b
and not matching for
select a,b from tab1
if i added two additional spaces its matching. It is clear that it is due to two \s that i have used. But, i want to make those optional as well.
Please help me. I could not understand the other posts on this topic in stackoverflow