javascript - Defining delimiter -


i have text in extract data, there problem: there similar parts, , can cause confusion in regex.

example:

header text data: 10 body  header text data: 10 body 

i'm simplifying, because not have permission display actual text

i want extract number after data, need delimit between header , body. this, using regex:

header[\s\s]*?data:\s(\d+)[\s\s]*?body 

working example: https://regex101.com/r/ts9gu6/1

but text may not have data, ends taking next: https://regex101.com/r/hm7fv9/1

is possible fix without using logic? read "unrolling loop"

thanks.

what need tempered greedy token:

header(?:(?!header)[\s\s])*data:\s(\d+)[\s\s]*?body 

demo

non-greedy quantifiers stop matching possible, don't affect when match starts. instead, have tell match except header.


Comments