问题描述:

I would like to capture the word "ABADDON", up to (not including ABAFT). I would then like to repeat this capture with "ABAFT", up to the next word (not including the next word). The words are capitalized.

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.

网友答案:

Hard to understand exactly what you mean, but here is a guess:

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

The capital word would be in the first capturing group, and the text following it in the second.

网友答案:

Taking off on @Qtax's answer, it could also be done like this:

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

taking it further, to be forgiving to formatting while mantaining general form:

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

相关阅读:
Top