使用'^'停止多个字符串和字符

时间:2017-01-05 04:27:43

标签: regex

我正在进行正则表达式操作,以阻止字符集{\t\t{

第一个没问题,但第二个不能像我一样使用^符号来实现。

我目前的正则表达式为[\t+]?{\d+}[^\{]*

正如您所看到的,我已将^有效地用于单个字符,但我无法将其应用于\t\t\{等字符串

如何应用当前正则表达式来考虑这两种可能性?

示例文字:

{1} The words of the blessing of Enoch, wherewith he blessed the elect and righteous, who will be living in the day of tribulation, when all the wicked and godless are to be removed. {2} And he took up his parable and said--Enoch a righteous man, whose eyes were opened by God, saw the vision of the Holy One in the heavens, which the angels showed me, and from them I heard everything, and from them I understood as I saw, but not for this generation, but for a remote one which is for to come. {3} Concerning the elect I said, and took up my parable concerning them:

        The Holy Great One will come forth from His dwelling,
        {4} And the eternal God will tread upon the earth, [even] on Mount Sinai,
        And appear from His camp
        And appear in the strength of His might from the heaven of heavens.

        {5} And all shall be smitten with fear
        And the Watchers shall quake,
        And great fear and trembling shall seize them unto the ends of the earth.

        {6} And the high mountains shall be shaken,
        And the high hills shall be made low,
        And shall melt like wax before the flame 

当我以多行提取方式执行此操作时,不会为每个块的第一行保留该子句。理想情况下,提取物应该停止\ t \ t \ t {允许它在下一次提取中正确拾取,创建完美的缩进块。原因是当它们从数据库中取出时,应该在第一行检测到\ t \ t以允许动态格式化。

1 个答案:

答案 0 :(得分:1)

[\t+]?{\d+}[\s\S]*?(?=\s*{|$)

你可以使用它。参见演示。

https://regex101.com/r/nNUHJ8/1