VBScript正则表达式模式

VBScript正则表达式模式,vbscript,Vbscript,我需要一个模式,做一个非常具体的事情,但几个小时后,我无法达到预期的结果 示例字符串: SELECT col1 FROM tbl1 WHERE col1 = (SELECT col2 FROM tbl2 WHERE col2=col2) 预期结果: FROM tbl1 WHERE col1 = (SELECT col2 FROM tbl2 WHERE col2=col2) -> tbl1 -> WHERE col1 = (SELECT col2 FROM tbl2

我需要一个模式,做一个非常具体的事情,但几个小时后,我无法达到预期的结果

示例字符串:

SELECT col1 FROM tbl1 WHERE col1 = (SELECT col2 FROM tbl2 WHERE col2=col2)
预期结果:

FROM tbl1 WHERE col1 = (SELECT col2 FROM tbl2 WHERE col2=col2)

    -> tbl1
    -> WHERE col1 = (SELECT col2 FROM tbl2 WHERE col2=col2)
实际模式:

FROM\s+([^\s,]+)[\s\S]+(WHERE[\s\S]+)
实际结果:

FROM tbl1 WHERE col1 = (SELECT col2 FROM tbl2 WHERE col2=col2)

    -> tbl2
    -> WHERE col2=col2)
我尝试过使用“前瞻”和其他功能,但我无法从第一个“位置”开始分组

注意:“tbl1”和“WHERE”之间应该匹配所有可能的内容,而不仅仅是一个空格


注2:它应该在第一个“WHERE”之后对所有内容进行分组,即使以后没有WHERE。

在发布更多详细信息之前,我声称非贪婪模式将解决此问题:

Option Explicit

Dim r : Set r = New RegExp
'r.Pattern = "FROM\s+([^\s,]+)[\s\S]+(WHERE[\s\S]+)"
r.Pattern = "FROM\s+([^\s,]+)[\s\S]+?(WHERE[\s\S]+)"
'Dim s : s = "SELECT col1 FROM tbl1 WHERE col1 = (SELECT col2 FROM tbl2 WHERE col2=col2)"
Dim s : s = "SELECT col1 FROM tbl1 WHERE col1 = (No  W h e r e  here)"
Dim m : Set m = r.Execute(s)
If 1 = m.Count Then
   Dim t : t = Join(Array("From", m(0).SubMatches(0), m(0).SubMatches(1), _
                          vbCrLf, vbCrLf, "->", m(0).SubMatches(0), vbCrLf, "->", m(0).SubMatches(1)))
   WScript.Echo s
   WScript.Echo t
Else
   WScript.Echo "no match"
End If
输出:

cscript 44890052.vbs
SELECT col1 FROM tbl1 WHERE col1 = (No  W h e r e  here)
From tbl1 WHERE col1 = (No  W h e r e  here)

 -> tbl1
 -> WHERE col1 = (No  W h e r e  here)

您应该发布一个具有代表性的输入/输出对列表,并至少提示您从匹配对象生成输出的策略。为什么使用VB6标记?即使使用第二个“where”,它也能很好地工作。谢谢!