Regex .NET Multiline Capture

时间:2011-11-30 17:15:14

标签: regex

我想捕捉“ABADDON”这个词,直到(不包括ABAFT)。然后我想用“ABAFT”重复这个捕获,直到下一个单词(不包括下一个单词)。这些词是大写的。

ABADDON
A*bad"don, n. Etym: [Heb. abaddon destruction, abyss, fr. abad to be
lost, to perish.]

1. The destroyer, or angel of the bottomless pit; -- the same as
Apollyon and Asmodeus.

2. Hell; the bottomless pit. [Poetic]
In all her gates, Abaddon rues Thy bold attempt. Milton.

ABAFT
A*baft", prep. Etym: [Pref. a-on + OE. baft, baften, biaften, AS.
beæftan; be by + æftan behind. See After, Aft, By.] (Naut.)

Defn: Behind; toward the stern from; as, abaft the wheelhouse. Abaft
the beam. See under Beam.

2 个答案:

答案 0 :(得分:1)

很难准确理解你的意思,但这是猜测:

(?ms)^([A-Z]+)$(.+?)(?=^[A-Z]+$|\z)

大写单词将位于第一个捕获组中,而后面的文本位于第二个捕获组中。

答案 1 :(得分:0)

起飞@ Qtax的答案,也可以这样做:

(?ms)^[A-Z]+$(?:(?!^[A-Z]+$).)*/^[A-Z]+$(?:(?!^[A-Z]+$).)*/ms

更进一步,在保持一般形式的同时宽容格式化:

(?ms)^[^\S\n]*[A-Z]+\s*$(?:(?!^[^\S\n]*[A-Z]+\s*$).)*

/^[^\S\n]*[A-Z]+\s*$(?:(?!^[^\S\n]*[A-Z]+\s*$).)*/ms