Regular expression to extract SQL query

后端 未结 5 895
青春惊慌失措
青春惊慌失措 2020-12-18 08:19

Is there a regex which extracts SQL queries from a string? I\'m NOT interested to validate any SQL syntax, rather and only extracting a selection o

5条回答
  •  旧巷少年郎
    2020-12-18 08:46

    (?m)^(UPDATE|SELECT|INSERT INTO).*;$ should work. This would extend the pattern to match over newlines. It should be able to loop through and find all your SQL.

    Looking at the example you provided it will match your commands until the ;. You can see the example used for testing here.

提交回复
热议问题