I am working on a site for cars. I wrote a regex which worked, up until the point where brands are separated by a hyphen.
These are 2 examples I want to match:
- class-s/ford-shelby-gt350r
- class-s/exotic-rides-w70
The regex I used for it is
([a-z-]+)\/([a-z]+[-]*[a-z]+)-([a-zA-Z0-9]+[-]*[a-z0-9]+)\/?$
But this matches Shelby as the brand and not as type.
This is how I use it inside Wordpress
$wp_rewrite->add_permastruct( 'cars', 'cars/%class%/%brand%-%postname%/', false );
add_rewrite_rule( 'cars/([a-zA-Z-]+)/([a-zA-Z]+)-([a-zA-Z0-9-]+)/?$', 'index.php?post_type=as_car&name=$matches[3]', 'top' );
I think I need to check (with a lookup) if the brand contains a hyphen, but I don't know how to do it.
Can someone help me do it ?
This is a link to my regex editor:
ADDED: I changed my code. I now generate a full post_name, so I don't have to regex anything...