-2

I have the following output:

WordA

1

2

3

4

WordB

5

6

7

8

WordC

9

10

11

12

WordA

13

14

15

16

WordB

I need to grab the numbers between the two words: WordA and WordB I tried (?<=WordA ).*(?= WordB) but the problem is, it grabs ALL the numbers here, including the ones between WordC and WordA that I don't want. I only want to grab the numbers between the 2 pairs which are 1 2 3 4 and 13 14 15 16

Any ideas?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
abracadab
  • 1
  • 2

2 Answers2

0

try this: (?<=WordA).*?(?=WordB).

0

First use this regex:

WordA(\s+\d+)+\s+WordB

this will cut you WITH WordA and WordB. Then cut the digits with this regex:

\d+

First you will get:

WordA

1

2

3

4

WordB

WordA

13

14

15

16

WordB

Second you will get:

1

2

3

4

13

14

15

16