Regular expression to find all table names in a query

前端 未结 12 990
一个人的身影
一个人的身影 2020-12-03 18:09

I am not that hot at regular expressions and it has made my little mind melt some what.

I am trying to find all the tables names in a query. So say I have the query

12条回答
  •  孤城傲影
    2020-12-03 18:46

    This will pull out a table name on an insert Into query:

    (?<=(INTO)\s)[^\s]*(?=\(())
    

    The Following will do the same but with a select including joins

    (?<=(from|join)\s)[^\s]*(?=\s(on|join|where))
    

    Finally going back to an insert if you want to return just the values that are held in an insert query use the following Regex

    (?i)(?<=VALUES[ ]*\().*(?=\))
    

    I know this is an old thread but it may assist someone else looking around

    Enjoy

提交回复
热议问题