Regex in PHP: How to get word in last part URL?

user4383842

I have some lines like this:

/gtrhr/5435-silent-library
/fghf3/435-silent-librar
/gfgr2gf/8768-silent-lib

How to get ONLY words in last part of URL ?

So, the oupout will be:

silent-library
silent-librar
silent-lib

Thank you !

Niels Keurentjes
[A-Za-z][A-Za-z\-]+$

The $ enforces the match ends with the end of the line.

See here on Regexr.

You could also go for a more general [a-z][\w\-]+$ but that depends on precisely which characters are valid or not in your inputs.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related