Regular expression to match all characters until next match

I am parsing text in which there are many repetitions of a simple template. The text has a script format for playback, for example:

SAMPSON
I mean, an we be in choler, we'll draw.

GREGORY
Ay, while you live, draw your neck out o' the collar.

I am currently using a template ([A-Z0-9\s]+)\s*\:?\s*[\r\n](.+)[\r\n]{2}that works great (explanation below), except when it comes to speech symbols. When this happens, the character name is captured successfully, but only the first line of speech is captured.

Enabling single-line mode (to enable line breaks in .) simply creates one giant match.

How can I say (.+)stop when he finds the next character name and finishes the match?
I repeat each match individually (JavaScript), so the name should be available for the next match.

Ideally, I could combine all the characters until the whole pattern is repeated.


Sample explained:

The first group corresponds to the name of the symbol (it allows uppercase letters, numbers and spaces), (with additional mutual and space).
The second group (character’s speech) begins with a new line and captures any characters (except for problem ones, line breaks and characters after them).
The pattern ends (and begins) after an empty line.

+5
source share
3 answers

, -, . , .

([A-Z0-9\s]+)\s*\:?\s*[\r\n]((.+[\r\n]?.*)+)[\r\n]{2}

, , . , .

0

. , . ( , "speaker" ):

results = "Insert script here".split(/^([A-Z]+)$/)

, , , , , :

results[0] = ""
results[1] = "SAMPSON"      
results[2] = "I mean, an we be in choler, we'll draw.            
"
results[3] = "GREGORY"      
results[4] = "Ay, while you live, draw your neck out o' the collar. "

, . XRegExp, - .

+1

, , , , .. - ,
- , , , ,

findAll - :

((?:[A-Z]{2,}\s*:?\s*)+)\s+((?![A-Z]{2,}\s*:?\s*).+?[.?!]\s*)+

:

  • ((?:[A-Z]{2,}\s*:?\s*)+) - - ​​ "GREGOR", "MANFRED THE GREATEST:"
  • \s+ -
    :
  • (?![A-Z]{2,}\s*:?\s*) - ,
  • .+?[.?!]\s* - , , [.?!]
0
source

All Articles