Match signs and parenthesis with regex
I've been working in .htaccess to make clean urls. Everything going perfect right now. Iv been able to make clean urls from all alfa-numeric characters with this regex /([a-zA-Z0-9\-]+)/
I want to add now parenthesis (
, )
, [
, 开发者_如何学C]
and the signs &
, %
, ;
and I have no idea how...
After some work I came with this regex expression: /([a-zA-Z0-9#%@()[]\-]+)/
.
But it does not seem to work,
I tried with regex tutorials and everything but I just don't get it.. If someone could help I will appreciate it
Try to delimit special characters. The first closed bracket is probably closing the list.
Untested:
/([a-zA-Z0-9#%@\(\)\[\]\-]+)/
Simplest version:
/([a-zA-Z0-9#%&@;()[\]-]+)/
You need to escape the reserved characters - inside of character classes, you need to escape ]
, -
, \
and ^
.
Your new regular expression would be: /([a-zA-Z0-9#%@()[\]\-]+)/
.
精彩评论