Here you go:
compare\/([^-vs-]*)(?:-vs-)([^-vs-]*)(?:-vs-)?([^-vs-]*)?
Remember to escape backslashes (as I have done). I also made your lookups more consistent in their internal logic/structure.
I assumed you wouldn’t want a second -vs- if the third product wasn’t there, so this is why you now have the second non-capturing group.
Here is a link with the answer in regex: https://regexr.com/3u465 to make things clear. Please let me know if I misunderstood your requirements. 🙂
Related Posts:
- Multiple post types – share same ReWrite slug?
- Need help with friendly URL’s in WordPress
- website with pretty permalinks except pagination
- add_feed rewrite overwriting standard permalinks
- Show post content in two different places without redirect
- Need help with add_rewrite_rule
- remove “index.php” from permalinks
- Custom pages with plugin
- Can a custom post type have a Parent Page?
- Custom rewrite rules for archive page and single post
- WordPress Rewrite Rules for Custom Post Type and Taxonomy
- Custom post type permalink endpoint
- Custom permalink structure only for default posts
- Regex in add_rewrite_tag not accepting OR operators?
- How to add a custom URL placeholder to author archives?
- How to modify URL structures in custom post types and taxonomies or terms
- Adding meta values to permalink
- Removing taxonomy base using WP rewrite
- URL Rewrite + Page + Custom Post Type = Unusual Redirect
- Make post slug have priority over category slug
- Permalinks so that one custom post type appears to be a child of another, not working
- Custom taxonomy on permalink
- Permalink rewrite with custom post type and custom taxonomy
- Custom post type permalink changing itself every other change
- How to build custom WP admin with custom URLs
- WordPress URL rewrite regex
- Prepend meta_value to permalink of post
- WordPress in “Couch Mode”?
- Using two permalinks for one post
- flexible rewrite ‘ramble’ URLs with WordPress
- Permalinks for CPT breaks permalinks to pages
- WP Rewrite Rules – Custom post type & taxonomy
- Remove base slug in CPT & CT, use CT in permalink
- Change the custom post type permalink
- Custom rewrite rules for feeds of custom queries (query_var query strings in URL)?
- Rewrite url / permalink for default archive – yearly / monthly
- WordPress Rewrite rule for nested post types
- Why does WordPress 3.0.4 keep deleting the contents of the .htaccess file?
- Permalinks, Rewrites, Get Variables, Oh My!
- Change permalink for a single post entry
- How to Modify Existing Rewrite Rules?
- Custom Permalink Tag breaks Pagination
- Add parent/child taxonomy to custom post type url
- rewrite_rule for custom post type doesn’t affect get_permalink
- Add ‘articles’ prefix before blog posts url without affecting pagination
- How can I rewrite a plugin generated URL?
- custom permalink/shortlink with base62 encoded post ID
- Custom Permalink for Taxonimie and Custom Post Type
- how to flush custom author rewrite rule
- How to change URL Custom Page?
- Add specific word to default page permalink
- Add filename to attachment page url
- add_rewrite_rule won’t work
- Remove Author Slug & Replace With Username
- When is it a good idea to build a permalink structure from scratch?
- WordPress not respecting template hierarchy (fetches index.php instead of single.php or page.php)
- How to properly rewrite url by custom var
- Call to a member function add_rule() on a non-object
- Why doesn’t flush_rewrite_rules run on plugin activation?
- I need a custom permalink for my website
- How to set up Author archives with sub category URL
- Creating Search Engine Friendly URL’s with Word Press
- Permalink Structure CPT With Custom Taxonomy Fails
- Permalinks: Page Not Found
- Rewrite rule to prettify two $_GET variables while in a new endpoint from a page
- Why is add_rewrite_endpoint incompatible with /%category%/%postname%/ permalink structure?
- Re-write specific custom post type category URL to go to another page
- Fatal error: Call to a member function add_rewrite_tag() on a non-object in /wp-includes/taxonomy.php on line 333
- Why is my mod_rewrite not working?
- Making a custom help center page
- WordPress custom post type permalink: website.com/post-name/post-id
- Remove custom taxonomy base from URL
- remove sub-category of Custom Post Type from permalink structure
- WordPress add_rewrite_rule() cannot visit lower url levels
- Custom rewrite_rules – only pass numbers and not alphabetic characters
- add_rewrite_rule not working for me
- Is a permastruct possible on pages?
- Using WP Rewrite, but just not “getting it”
- Rewrite rule for a query string
- WordPress slugs and 404 handling takes preference over folders in site root?
- How to encode author ID in the author permalink
- How to change custom post type permalink structure
- URLs and navigation in custom themes
- Custom permalinks with hierarchical taxonomy – getting PHP warning
- Share same Slug for a Custom Post Type and 2 Taxonomies
- How can I use get_post_meta with add_rewrite_rule to build custom permalinks?
- rewrite URL based on selected taxonomy for post page
- Can’t get custom rewrite tag, query var, permastruct (permalink structure), and rewrite rule to work properly together
- Use same slug base for Custom Post Type posts, and multiple taxonomy terms
- How can achieve this permalink perfectly? domain.com/%category%/%post-name%
- How to remove specific category from URL in WordPress
- Changes in permalink structure in WordPress and how to apply to in-site links
- WordPress Persistent connection rule does not work for “posts”
- Customize Custom Post Type URL
- Rewrite CPT permalinks and include WPML language
- redirect post id to post full url
- Custom Permalinks with CPT and Hierarchical Taxonomies
- Rewrite query string to path
- Custom permalink leads to index page
- Rewrite rule intended for CPTs gives 404 for pages