0

This is my multi-line text:

Route Segment: 1
10601 Derecho Dr, Austin, TX 78737, USA to Zilker Nature Preserve, 301 Nature Center Dr, Austin, TX 78746, USA
12.8 mi

Route Segment: 2
Zilker Nature Preserve, 301 Nature Center Dr, Austin, TX 78746, USA to Roy and Ann Butler Hike and Bike Trail, 900 W Riverside Dr, Austin, TX 78704, USA
2.0 mi

Route Segment: 3
Roy and Ann Butler Hike and Bike Trail, 900 W Riverside Dr, Austin, TX 78704, USA to East Austin, Austin, TX, USA
4.4 mi

I would like to use regex to extract the first address of each segment from the text:

10601 Derecho Dr, Austin, TX 78737, USA
Zilker Nature Preserve, 301 Nature Center Dr, Austin, TX 78746, USA
Roy and Ann Butler Hike and Bike Trail, 900 W Riverside Dr, Austin, TX 78704, USA

This is the regex I am using:

(?:Route Segment: \d)([\S\s]*?)to

It is only capturing the first instance instead of all instances, it's including Route Segment:\d and to, and I want to capture what's in between, not including, those strings.

I am using the javascript regex engine (regexr.com)

  • You pattern is fine, use it with a global modifier, see how to use it in code to get your results in [this answer](https://stackoverflow.com/a/40782646/3832970) (see bottom), or see [this thread](https://stackoverflow.com/questions/432493/how-do-you-access-the-matched-groups-in-a-javascript-regular-expression) – Wiktor Stribiżew May 14 '20 at 20:05
  • Hmm, I looked at that answer but it doesn't seem to be speaking to my situation of finding content between (and not including) two strings. Also, I saw an example of finding one instance but I didn't see an example of using a "global modifier." I would love to keep this question open until I find a solution. I'm not very good at regex. – Harrison Alley May 14 '20 at 20:14
  • Look, there are `exec` in a loop, `matchAll` examples, use any you want. E.g. `Array.from([...text.matchAll(/(?:Route Segment: \d)([\S\s]*?)to/g)], m=>m[1])` – Wiktor Stribiżew May 14 '20 at 20:19
  • Sorry, you tagged the question as JavaScript, but it appears you are using something else. Please show how and where you are using the regex. Also, try `/(?<=Route Segment: \d)[\S\s]*?(?=to)/g` – Wiktor Stribiżew May 14 '20 at 20:44

0 Answers0