katie
katie

Reputation: 1041

Regex - Invalid target for quantifier

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?

Upvotes: 4

Views: 4737

Answers (2)

hwnd
hwnd

Reputation: 70732

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

Upvotes: 4

AbraCadaver
AbraCadaver

Reputation: 78994

Try another regex site:

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

Regular expression visualization

Debuggex Demo

Upvotes: 1

Related Questions