Regex匹配行的结尾,除非以结束的括号结尾

问题描述 投票:0回答:1

我正在尝试编写一个JavaScript正则表达式,它将捕获一行的末尾,除非该行以右括号结束,例如:

[word]
lengthy text line

[other word]
even lengthier text line! Whoo!

这部分我不愿意写此正则表达式new RegExp(/[\n]\n|(?![^\]])$/gm)

但是即使在没有双倍空格的情况下,我也必须能够抓住行尾,并且事实证明超级困难,因为我对Regex并不了解。

                                        --   [word]
These two lines need to be grouped      --   lengthy text line

                                        --   [other word]
These two lines need to be grouped      --   even lengthier text line! Whoo!
This needs to be it's own group         --   This text line is the longest of them all!
                                        --   [more words]
These two lines need to be grouped      --   The last guy can win...

令人讨厌的是,有一个非常简单的Regex可以实现此目标,但是FireFox当前不支持它,这是一个问题。 (?<!])\n断言背后的负面表情

javascript regex regex-lookarounds
1个回答
0
投票

您正在寻找这样的正则表达式:

/^\[.+(\n+[^\[]+)/gm

演示:https://regex101.com/r/c1giqu/3

© www.soinside.com 2019 - 2024. All rights reserved.