Capture with regex a certain part of the string

2

In this sentence, /comprar/volkswagen/gol/11184529 , I would like to capture if there is the word comprar what comes next without the / , that is, I would like to capture the word volkswagen (but could be another

    

asked by anonymous 08.06.2018 / 21:01

1 answer

4

Regex ^\/comprar\/([^\/]+)\/([^\/]+)\/\d+$ . Then get the first and second group.

Take ^ and $ if it is not just one occurrence per line.

    
08.06.2018 / 21:07