Johncze
Johncze

Reputation: 469

Regular expression match over multiple lines

My goal is match text inside parentheses (including them). This pattern works fine:/(\-?\(.*\))/gm, although it doesn't work on multiple lines.

Any ideas how to also "catch"

(INDISTINCT ANNOUNCEMENT
          OVER PA)

?

Here is the sample:

365
00:22:20,105 --> 00:22:21,772
         (CLAMOURING)

366
00:22:21,774 --> 00:22:25,009
      (INDISTINCT ANNOUNCEMENT
      OVER PA)

367
00:22:55,340 --> 00:22:58,509
      (INDISTINCT ANNOUNCEMENT
      OVER PA)

368
00:23:10,655 --> 00:23:11,389
      SARAH: Excuse me.

Example on regex101.com

Upvotes: 1

Views: 55

Answers (2)

alpha bravo
alpha bravo

Reputation: 7948

As mentioned in the comments, . does not match the newline character. However, you can use [^)] to match everything except ), including newlines. e.g.

\([^)]*\)

Demo

Upvotes: 0

anubhava
anubhava

Reputation: 784878

You can use this regex to match content between ( and ) including newlines:

/\([\s\S]*?\)/g

In the absence of dotall flag in Javascript we use [\s\S] to make it match newlines as well.

RegEx Demo

Upvotes: 2

Related Questions