Skip to content
Advertisement

How to get index of regex match of only the matched and included part?

JavaScript

I am doing:

JavaScript

I want the index to end at Airport of destination.

Desired output:

JavaScript

Advertisement

Answer

You may move .* into the lookahead to avoid consuming that part of the match:

JavaScript

See a regex demo and a Python demo:

JavaScript
Advertisement