V
V
Valery Pavlenko2018-07-03 11:40:54
Regular Expressions
Valery Pavlenko, 2018-07-03 11:40:54

How to extract news ID from URL?

Hello!
Can you please tell me how to extract the news ID, which is after the second slash before the hyphen, using regular expressions?
Initial data :

site.com/cat/36814-antonov-polnaya-ahineya.html
site.com/80-90/36460-dobrynin-polnaya-ahineya.html
site.com/cat/4415-pyryshki.html

The end result should be :
36814
36460
4415

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nick Sdk, 2018-07-03
@trudogolik

/site[.]com\/[^\/]+\/(\d+)/
https://regex101.com/r/mNbLlo/1

R
Rsa97, 2018-07-03
@Rsa97

/\/(\d+)-[^\/]*$/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question