-1

I'm trying to use this regular expression in Java

(?<=((FROM[ \n\r]+)|(JOIN[ \n\r]+)|(APPLY[ \n\r]+)))((.?([a-zA-Z0-9_]+|([[a-zA-Z0-9._[]\s\$(){}+\?\<>|!]+])|("[a-zA-Z0-9._[]\s\$(){}+\?\<>|!]+")))+)

, to get the tables inside a SQL, and I get the following error:

Unable to execute regular expression.
java.util.regex.PatternSyntaxException:
Unclosed character class near index 147

I can't find the error.

Thanks for your help in advance

rici
  • 219,119
  • 25
  • 219
  • 314
Madmartigan
  • 441
  • 1
  • 5
  • 14
  • `[` and `]` inside character classes must be escaped. – Wiktor Stribiżew May 25 '22 at 16:01
  • 1
    A bad idea to use regex for this task. Use something like [JSqlParser](https://github.com/JSQLParser/JSqlParser) . An example how to extract table names [extract-table-names-from-sql](https://github.com/JSQLParser/JSqlParser/wiki/Examples-of-SQL-parsing#extract-table-names-from-sql) – Eritrean May 25 '22 at 16:05

0 Answers0