View Full Version : regexp Named Groups Fail Everywhere

16th August 2009, 01:05
Text = 123-45-6789

The object is to make sure that the separator (or lack of) between 45 and 6789 is the same as between 123 and 45

\d{3}(?<xxx>[ -]?)\d{2}\k<xxx>\d{4} and \d{3}(?'xxx'[ -]?)\d{2}\k'xxx'\d{4}
both fail, but

\d{3}([ -]?)\d{2}\1\d{4} works just fine

Eliminating the \k<xxx> doesn't help. The rejection seems to be triggered by the appearance of (?

I cannot get a match in Qt, on any web regex validator, or anywhere else. Does anyone know what's wrong with this simple regex/text combination?

16th August 2009, 09:57
looking at the docs of QRegExp, I can't find anything suggesting support of named captures. You can use \1,\2 ... to refer to a capture in the regex

d{3}([ -]?)\d{2}\1\d{4}

16th August 2009, 18:04

I should know better than to forget RTFM. Your post got me to a regex feature comparison that pointed out that QRegExp does NOT currently support named capture. Apparently it was a coincidence that the sites I tried also did not support the feature.

Thanks, although I'm embarrassed, I really appreciate your reply...