Sebastian
Sebastian

Reputation: 625

/0123456789.html get Number with regex

I really don't get it, probably I will never understand regex. Sorry!

If I have a string like

/0123456789.html

I want to excerpt the number. The length has 8-10 digits. With

\/[0-9]{8,10}(?:.html)

I get the whole part, but I just want the period of numbers (here 0123456789).

Upvotes: 0

Views: 66

Answers (1)

Zenoo
Zenoo

Reputation: 12880

You can use the RegEx (?<=\/)\d{8,10}(?=\.html)

  • (?<=\/) makes sure there is a / before your match

  • \d{8,10} matches a digit between 8 and 10 times

  • (?=\.html) makes sure your match is followed by .html

Demo.

Upvotes: 1

Related Questions