php - Codeigniter Routing with PCRE -
i trying create routing rule in codeigniter installation uses pcre.
what trying match this
http://example.com/segment1/segment2/(capturethis)
so can use "capturethis" portion input method. want make match if "segment1" not "admin". there may number of segments. represent segment ([^/]*)
, other "/" while using "/" in between each ([^/]*)
.
at first thinking of writing expression did not match "admin" or "/" [^[\/|admin]\/]*([^\/]*)
had no luck.
after looking around believe might achieved using negative lookbehind, i'm having trouble figuring out how this. trying ^(?<!/|i/admin/)[/([^/]*)]*
leave me potentially unknown amount of captured segments , need last without knowing how many there are.
has done before or knows how this? i'm sure i'm on looking simple, not fluent in regex i'd be.
update:
thank update on how codeigniter handles routes..i think should on same page now. ^
character has special meanings in character classes , won't have affect expect in lookarounds..also, shouldn't necessary since using negative lookahead ((?!...)
). however, said, (?!admin)([^/]*)
still has issues since [^/]*
match dmin
because when @ character d
not followed admin
. solve this, want positive lookbehind assertion also. make sure either right after beginning of string or forward slash (d
wouldn't match in case, since right after a
):
(?!admin)(?<=^|/)([^/]*)
you can't throw admin
in character class think, since a
, d
, m
, i
, or n
. however, close negative lookarounds. key remember these zero-width assertions , not match characters. in case want use negative lookahead. because begin match new segment following /
, want make sure point on (ahead) admin
not matched..if isn't matched, can continue capture ([^/]*)
typically do.
i'm not versed in codeigniter, may not need use in routing..but should show how works:
/(?!admin)([^/]*)
Comments
Post a Comment