Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[^/]+ explanation in htaccess

I have this htaccess code

RewriteRule   ^/([uge])/([^/]+)$  /$1/$2/

But I couldn't really understand what does [^/]+ do? I've been searching this on Google for awhile, but I couldn't get what I wanted.

like image 641
Jayson Tamayo Avatar asked Feb 13 '12 09:02

Jayson Tamayo


Video Answer


2 Answers

You have two basic regex constructs here

Character class

See character classes on regular-expressions.info

[...] is a character class, means this construct matches one character from the class (from inside the square brackets).

Your class starts with a ^, that gives the character class a special meaning, its a negated character class ([^...]), means matches anything thats not part of the class.

Quantifier

See quantifiers on regular-expressions.info

+ is a quantifier, meaning 1 or more

Meaning of your regex

To understand what this is doing you have also to take the next thing into account, the $ at the end. This is an anchor that matches the end of the string.

See anchors on regular-expressions.info

so ([^/]+)$ matches all characters at the end of the string that are not slashes.

Here you can also find a basic tutorial

like image 139
stema Avatar answered Nov 07 '22 00:11

stema


[^/] means any character not matching /.

like image 38
freedev Avatar answered Nov 07 '22 01:11

freedev