Title: Regex expression
Last modified: August 22, 2016

---

# Regex expression

 *  [ricardo.carrillo](https://wordpress.org/support/users/ricardocarrillo/)
 * (@ricardocarrillo)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/regex-expression/)
 * Hello!
 * I would like to use the php add_rewrite_rule function, but is very difficult 
   for me getting the regex expression.
 * This are some examples of the regular expressions I’m trying to get:
 * compare-nikon-d500-with-canon-eos-1200d –> compare/?c1=nikon-d500&c2=canon-eos-
   1200d
 * compare-panasonic-lumix-dmc-50-with-sony-a500 –> compare/?c1=panasonic-lumix-
   dmc-50&c2=sony-a500
 * Please, can you help me?
 * Thanks and sorry about my english

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Konstantin Kovshenin](https://wordpress.org/support/users/kovshenin/)
 * (@kovshenin)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/regex-expression/#post-5745023)
 * #^/compare-([a-z0-9-]+?)-with-([a-z0-9-]+)/?$#i so c1 and c2 will be in matches[
   1] and matches[2] respectively.
 *  Thread Starter [ricardo.carrillo](https://wordpress.org/support/users/ricardocarrillo/)
 * (@ricardocarrillo)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/regex-expression/#post-5745096)
 * Thank you for the answer, Konstantin.
 * This is the code in my functions.php
 *     ```
       function custom_rewrite_basic() {
         global $wp_rewrite;
         add_rewrite_rule('^/comparar-([a-z0-9-]+?)-con-([a-z0-9-]+)/?$', '/comparar/?c1=$matches[1]&c2=$matches[2]');
         $wp_rewrite->flush_rules( false );
       }
       add_action('init', 'custom_rewrite_basic');
       ```
   
 * But it should be something wrong because is not working. Any idea?
 * Thanks again

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Regex expression’ is closed to new replies.

## Tags

 * [regex](https://wordpress.org/support/topic-tag/regex/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [ricardo.carrillo](https://wordpress.org/support/users/ricardocarrillo/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/regex-expression/#post-5745096)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
