A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://stackoverflow.com/questions/6971287/named-capture-in-php-using-regex below:

Named capture in PHP using regex

Doesn't work with replace , only useful for match in php

$test="yet another test";

preg_match('/(?P<word>t[^s]+)/',$test,$matches);

var_dump($matches['word']);

answered Aug 7, 2011 at 7:23

Dreaded semicolonDreaded semicolon

2,31411 gold badge2929 silver badges4444 bronze badges

5

According documentation

PHP 5.2.2 introduced two alternative syntaxes (?<name>pattern) and (?'name'pattern)

So you'll get same result using:

<?php
preg_match('/(?P<test>.+)/', $string, $matches);  // basic syntax
preg_match('/(?<test>.+)/', $string, $matches);   // alternative
preg_match("/(?'test'.+)/", $string, $matches);   // alternative

Check result on 3v4l.org

answered Nov 22, 2017 at 11:41

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4