0
I get some help in putting the correct delimiters below:
if (preg_match('/^[a-zA-Z0-9_-]+[/]{1}[a-zA-Z0-9_-]+$', $bloco)) {
....
}
0
I get some help in putting the correct delimiters below:
if (preg_match('/^[a-zA-Z0-9_-]+[/]{1}[a-zA-Z0-9_-]+$', $bloco)) {
....
}
3
You placed the delimiter at the beginning of the expression, the same delimiter is missing at the end. Also, you did not escape the slash (/
).
'/^[a-zA-Z0-9_-]+\/{1}[a-zA-Z0-9_-]+$/'
Another thing: when you require a single occurrence of a character, it is not necessary to use quantifiers. Then, your expression would look like this:
'/^[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+$/'
Finally, one last improvement: you can replace the Character ranges by character classes:
a-zA-Z
for \w
0-9
for \d
So your expression would look like this:
'/^[\w\d_-]+\/[\w\d_-]+$/'
Browser other questions tagged php regex
You are not signed in. Login or sign up in order to post.
Thank you, but you’ve returned an error : Warning: preg_match() [Function.preg-match]: Unknown Modifier ']'
– user22753
"/" was missing. I changed the answer.
– Rodrigo Rigotti