I need a regular expression that matches the end of a URL in the following format:
/somente-letras/somente-numeros[/]
To combine the part of somente-letras
, I used ~^/[A-Z]+$~
, however from the moment I put a bar, nothing else works.
The tests I did:
URL: /testando-minha-url
REGEX: ~^/[a-z-]+$~
SAÍDA: true
Placing a slash at the end of the URL
URL: /testando-minha-url/
REGEX: ~^/[a-z-]+$~
SAÍDA: false
Placing a slash in the expression
URL: /testando-minha-url/
REGEX: ~^/[a-z-]/+$~
SAÍDA: false
That is, my problem is from the forward slash.
Then after the toolbar, I need to match only numbers, and possibly which endbar is optional, work with or without it.
I'm using the preg_math
function of PHP, preg_match($regex, $str)
Is it possible? Where am I going wrong?