Reputation: 1527
I have a database query which looks like this
select * from students join (select * from teachers) join (select * from workers
I had a requirement to tokenize this string based on 'select'.
I am trying regex (select)(.*?)((?:select)|$)
, ut it is matching only 2 times.
Request some pointers on how to achieve this.
I need the 3 output tokens as below
select * from students join (
select * from teachers) join (
select * from workers
Upvotes: 0
Views: 98
Reputation: 11132
I think this regex will work:
select.*?(?=select|$)
The regex matches the word select
, then any text (not including new lines) up until right before the next select
or the end of the string.
Demonstration here: http://regex101.com/r/sR3gV1
Upvotes: 2
Reputation: 39355
If you are trying to parse the select queries from the string then you can use this regex. Assuming you are not doing select from multiple tables(i.e. not doing select * from x,y,z
)
(select.*?from\\s+\\w+)
Upvotes: 0