Forum Moderators: phranque
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
> 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]
Jim