Regular expression to extract SQL query

后端 未结 5 901
青春惊慌失措
青春惊慌失措 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:29

    If you're dealing with a language, create a lexer that tokenizes your string. Use JFlex, which is a lexical analyzer generator. It generates a Java class that splits a string into tokens based on a grammar specified in a special file. Take the relevant grammar rules from this file.

    Parsing is a separate process than tokenization (or lexical analysis). You might want to use a parser generator, after lexical analysis, if lexical analysis is not enough.

提交回复
热议问题