[^ /] + htaccess explanation

I have this htaccess code

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

But I could not understand what was doing [^/]+? I searched this on Google for a while, but I couldn’t get what I wanted.

+5
source share
5 answers

Here you have two basic regex constructs

Character class

See character classes at regular-expressions.info

[...] is a character class, means that this construction corresponds to one character from the class (inside square brackets).

Your class begins with ^, which gives the character class a special meaning; its negative character class ( [^...]) means matching anything that is not part of the class.

Quantifier

. regular-expressions.info

+ - , 1

, , : $ . , .

regular-expressions.info

([^/]+)$ , .

+7

[^/] , /.

+5

:

1 , /

, [ ] ^ , , :

[^/] , /

[^/]+ 1 , /

+4

[any_character] - charclass Ref. [^any_character] - charclass negated Ref.

Anchors Ref:

^ : ^ (), .

charclass Ref: :

, (]), (), (^) (-). . [+ *]. , , .

Ref
+ .

[^/]+

, /. , , /.


^/([uge])/([^/]+)$

  • /
  • followed by u or g or e
  • then /
  • follows and ends with one or more characters other than /

()(parentheses) are used for: parentheses Create a backlink Ref

+3
source

An expression [^/]matches any character that is not /, and a quantifier +means that the expression to the left of the quantifier must appear once.

+2
source

All Articles