How can I capture a word just after specific word in regex, I have to select everything between from - to and after to so there will be two capturing groups.
Example:
"From London to Saint Petersburg" I wanted to extract London
Saint Petersburg
from above string.
Im stuck with this code here, my current regex selecting to Saint Petersburg
i wanted to get rid word from
and to
from the selection.
/(?=to)(.*)/i
You can capture the two groups you need and then use match
to extract them:
s = "From London to Saint Petersburg"
console.log(
s.match(/From (.*?) to (.*)/).slice(1,3)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With