Results 1 to 3 of 3

Thread: regexp Named Groups Fail Everywhere

  1. #1
    Join Date
    Jul 2009
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default regexp Named Groups Fail Everywhere

    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

    Regex's
    \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?

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: regexp Named Groups Fail Everywhere

    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

    Qt Code:
    1. d{3}([ -]?)\d{2}\1\d{4}
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to caduel for this useful post:

    jc (16th August 2009)

  4. #3
    Join Date
    Jul 2009
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Red face Re: regexp Named Groups Fail Everywhere

    Caduel,

    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...

    -jc

Similar Threads

  1. Fail to compile something rely on Qt4
    By kfc123 in forum Installation and Deployment
    Replies: 1
    Last Post: 2nd July 2009, 20:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.