Forum Moderators: phranque

Message Too Old, No Replies

Need help tying loose ends on rewrite rule

         

ntbgl

12:51 am on Feb 18, 2009 (gmt 0)

10+ Year Member



RewriteRule ^(b¦g-[bg,]{1,3}-([a-z]{3},?)-[clr,]{1,5})/$/index.php?var=$1

I need help with my regular expression. I have most of it down, but there's a lot of loose ends I'm hoping someone might be able to help me with.

The string has four parts to it, with a dash between each part.

The first part is either "b" or "g".

This is followed by a "-".

The second part is either "b", "g", or "b,g".

The third part is atleast one three letter combination, such as "xyz". There can be multiple three letter combinations, but they must be seperated by a ",". For example "xyz", or "xyz,abc" or "xyz,abc,def".

This is followed by a "-".

The last part is either a "c", "l", or "r", or any combination of those letters seperated by a ",". For example "c", "l", "r", "c,l", "c,l,r", "c,r", "l,r"

Again, I think I'm close but I do know there are some loose ends. Any help is much appreciated. Thanks

jdMorgan

2:02 am on Feb 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Divide and conquer:

> The first part is either "b" or "g".
> This is followed by a "-".
[bg]-

> The second part is either "b", "g", or "b,g".
> [This is followed by a "-".] (Looking at your code above, I assume you omitted this line accidentally)
([bg]¦b,g)-

> The third part is at least one three letter combination, such as "xyz". There can be multiple three letter combinations, but they must be separated by a ",". For example "xyz", or "xyz,abc" or "xyz,abc,def".
This is followed by a "-".
([a-z]{3},)*[a-z]{3}-

> The last part is either a "c", "l", or "r", or any combination of those letters separated by a ",". For example "c", "l", "r", "c,l", "c,l,r", "c,r", "l,r"
([clr],){0,2}[clr]
This pattern is not exact, as it does not enforce mutual exclusion, so might need more work, such as
(c,l,r¦c,[lr]¦c¦l,r¦[lr]) if the letters are always in the order "c, l, r" when they are present (this wasn't completely clear from the description).

---

Add start anchor, outer parentheses, and end-anchor, and combine the above sub-patterns:


RewriteRule ^([bg]-([bg]¦b,g)-([a-z]{3},)*[a-z]{3}-([clr],){0,2}[clr])$ /index.php?var=$1 [L]

Important: Change the broken pipe "¦" character in the second group to a solid pipe character before use; Posting on this forum modifies the pipe character.

Jim

ntbgl

2:59 am on Feb 19, 2009 (gmt 0)

10+ Year Member



You have no idea how much you've helped me! Thank you so much!