i am searching for a regular expression which removes an x at the beginning of a path. Accepted path separators are \, / and . The path can also start with one of these separators but it don't have to.
According to regexpal it is working but PHP throws the following error:
Compilation failed: missing terminating ] for character class at offset 24
and here is the regex:
/^([\/\.\\]?)X([\/\.\\]{1})/i
What's wrong with this regex?
You are escaping ] at the end
You can instead use preg_quote() which puts a backslash in front of every character that is part of the regular expression syntax.
Also, there's no need to escape .(if it's is in character class)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With