Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex - Invalid target for quantifier

Tags:

regex

php

I have this simple regular expression, and I'm testing it on RegExr.

^(?<name>[a-z0-9\-]+)

It should give me an associative array with a name field that matches strings that contains a-z and 0-9.

But I get the ? character underlined in red with that error.

Why?

like image 458
katie Avatar asked Sep 17 '25 03:09

katie


1 Answers

Well unfortunately, RegExr v2 is dependent on the JS RegExp implementation, which does not support named capture groups. See your working regular expression at regular expressions 101

like image 120
hwnd Avatar answered Sep 18 '25 16:09

hwnd