[英]Javascript regex - how to match when no trailing spaces
In this regex I'm trying to extract the list of tables from a SQL select statement. 在此正则表达式中,我尝试从SQL select语句中提取表列表。 It works fine with one exception, if the statement ends with the table name there is no match.
如果该语句以表名结尾,则没有匹配项,但有一个例外,它可以正常工作。 For example:
例如:
Given he regex: 鉴于他正则表达式:
(?:from|join)\s+(.*?)(?:\)|\s+(?:where|on|inner|outer|full|left|right|join|\s*$))
and given this string: 并给出以下字符串:
"select xxxx from table1 t1, table2, table3 t3 " (note the last space)
The match is: 匹配为:
"table1 t1, table2, table3 t3"
But given this string: 但鉴于此字符串:
"select xxxx from table1 t1, table2, table3 t3" (without last space)
There's no match. 没有比赛。 How to make this work?
如何使这项工作?
RegEx isn't very good at this, as it's a lot more complicated than it appears: 正则表达式不是很好,因为它比看起来复杂得多:
What you can do is an sql parser, and there is a good one Hrer . 您可以做的是一个SQL解析器,并且有一个很好的Hrer 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.