---
title: "What I Learned Today: Regular Expression Backreferences"
description: This is another post in my challenge to learn something new every day and then share that in a blog post.
---

[Blog ](https://www.metaltoad.com/blog)

# [What I Learned Today: Regular Expression Backreferences](https://www.metaltoad.com/blog/what-i-learned-today-regular-expression-backreferences)

 Written by [Metal Toad Staff](https://www.metaltoad.com/blog/author/metal-toad-staff) | Sep 10, 2013 12:00:00 AM

This is another post in my [challenge to learn something new every day](https://www.metaltoad.com/blog/always-learning-always-sharing) and then share that in a blog post.

This is fairly simple, but even though I'm comfortable with regular expressions, I was not familiar with the "?:" syntax (aka: question mark colon). I was working on some Behat tests using the MinkExtension, and this is used fairly often in the code `(?P<option>(?:[^"]|\\")*)`.

The `?P<option>` portion says to [name the group](http://www.regular-expressions.info/named.html) enclosed by parenthesis "option", so in PHP in will be in the variable $option. The `?:` portion says to not capture that group enclosed by parenthesis in a [backreference](http://www.regular-expressions.info/brackets.html). Besides being an optimization for the regular expression engine, it could be helpful to use this when doing a [preg_match](http://php.net/preg_match) to only extract the groups that you want.

*This post is part of my challenge to [never stop learning](https://www.metaltoad.com/blog/always-learning-always-sharing).*

[View full post](https://www.metaltoad.com/blog/what-i-learned-today-regular-expression-backreferences)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Metal Toad Staff"
  },
  "dateModified" : "2023-12-06T23:25:11.522Z",
  "datePublished" : "2013-09-10T00:00:00Z",
  "headline" : "What I Learned Today: Regular Expression Backreferences",
  "image" : {
    "@type" : "ImageObject",
    "height" : 500,
    "url" : "https://6104926.fs1.hubspotusercontent-na1.net/hubfs/6104926/Imported_Blog_Media/Metal_Toad_blog_generic-Aug-11-2023-10-02-31-1838-PM.jpg",
    "width" : 870
  },
  "mainEntityOfPage" : "https://www.metaltoad.com/blog/what-i-learned-today-regular-expression-backreferences",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60.0,
      "url" : "https://6104926.fs1.hubspotusercontent-na1.net/hubfs/6104926/social-suggested-images/6104926.fs1.hubspotusercontent-na1.nethub6104926hubfsMetal_Toad_Logo_orange_horizontal-50-1.jpg",
      "width" : 240.00002
    },
    "name" : "Blog"
  }
}
```