Vbscript 正则表达式 - 匹配 [下一页]

Vbscript Regular Expressions - Matching [nextpage]

我正在尝试从 CMS 获取输入并将其转换为多个页面。我打算如何尝试编写一个正则表达式,通过查找 [nextpage] 将每个 "page" 提取到数组中。我可以非常接近,但输出不是我想要的。

假设这个内容例如:

我们美国人民,为了组成 [下一页] 一个更完美的联邦,建立正义,确保国内安宁,提供共同防御,促进普遍福利,并确保自由的祝福 [ nextpage] 为了我们自己和我们的后代,为美利坚合众国制定并制定这部宪法。

我当前的正则表达式:

/(.*?)\[nextpage](.*?)/

我想要的结果:

[0] = 我们美国人民,为了形成

[1] = 一个更完美的联盟,建立正义,确保国内安宁,提供共同防御,促进普遍福利,并确保自由的祝福

[2] = 为了我们自己和我们的后代,为美利坚合众国制定并制定这部宪法。


谢谢。

这似乎更容易。

Dim B
A = "Whereas the people of New South Wales, Victoria, South Australia, Queensland, and Tasmania, humbly relying on the blessing of Almighty God, have agreed to unite in one indissoluble Federal Commonwealth under the Crown of the United Kingdom [nextpage] of Great Britain and Ireland, [nextpage] and under the Constitution hereby established:"
B = Split(A, "[nextpage]")
Count = 0
For each term in B
    msgbox Count & " = " & term
    Count = count+1
Next

根据我的评论发布此内容。

however there is always an empty result at the end.

当然,.*? 允许 [nextpage][nextpage] 之间的空内容。

如果你想删除尾随空白,只需使用 (.*?)(?:\[nextpage\]|$)(?<=.)

这也将修复最后多余的空匹配。

VBscript 更新

显然 VBscript 与 JScript 一样是垃圾。

在那种情况下,你必须使用这个 (.*?(?=\[nextpage\])|.+)(?:\[nextpage\]|$)

注意 - 如果您希望匹配跨行,您可以使用 [\S\s] 代替正则表达式中的点 .

([\S\s]*?(?=\[nextpage\])|[\S\s]+)(?:\[nextpage\]|$)