Results 1 to 3 of 3

Thread: Implement a regex in QRegExp

  1. #1
    Join Date
    Jun 2011
    Posts
    69
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Question Implement a regex in QRegExp

    Here is the regex and how i use it.
    Qt Code:
    1. QString regexPattern =
    2. "^(?:http|ftp)s?://" // http:// or https://
    3. "(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\\.)+(?:[A-Z]{2,6}\\.?|[A-Z0-9-]{2,}\\.?)|" // #domain...
    4. "localhost|" // localhost...
    5. "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})" // ...or ip
    6. "(?::\\d+)?" // optional port
    7. "(?:/?|[/?]\\S+)$";
    8. _regexValidator = new QRegExpValidator(QRegExp(regexPattern), this->parent());
    To copy to clipboard, switch view to plain text mode 

    Problem is that the QRegExpValidator::validate() never returns Acceptable.
    I don't know what part i missing in it.
    Also the regex is for URL validation ;)

    For the record, the regular experssion itself is stolen from django.core.validators.URLValidator
    Last edited by Alir3z4; 27th April 2012 at 02:53.
    ...یه مرد هیچوقت زمین نمیخوره

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Implement a regex in QRegExp

    For a start your regular expression is broken and your compiler is probably warning you about an unknown escape "\.". You need to double-up the \\ before the periods in the domain name and ip address.

    Once you have that fixed, your domain name would have to be all upper-case.

  3. #3
    Join Date
    Jun 2011
    Posts
    69
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Implement a regex in QRegExp

    Quote Originally Posted by ChrisW67 View Post
    For a start your regular expression is broken and your compiler is probably warning you about an unknown escape "\.". You need to double-up the \\ before the periods in the domain name and ip address.

    Once you have that fixed, your domain name would have to be all upper-case.
    Actually no, the compiler didn't warn me about unknown escape, beside that i did try also double slash \\. but no didn't work.
    As you said i tried to make domain In upper-case, but the results was same !
    And something else can somehow make that regex case-insensitive by the QRexExp itself?

    Update:
    Yes you were right, i just:
    Qt Code:
    1. _regexValidator = new QRegExpValidator(QRegExp(regexPattern, Qt::CaseInsensitive), this->parent());
    To copy to clipboard, switch view to plain text mode 
    and make it CaseInsensitive , and now it works. i should test it more.
    Thanks ChrisW67
    ...یه مرد هیچوقت زمین نمیخوره

Similar Threads

  1. Regex to filter words containing english alphabets
    By dipeshtech in forum Qt Programming
    Replies: 12
    Last Post: 1st April 2011, 00:24
  2. Partial matching of regex
    By ehamberg in forum Qt Programming
    Replies: 1
    Last Post: 28th May 2008, 20:13
  3. Having a brain cramp on a regex
    By Spockmeat in forum Qt Programming
    Replies: 2
    Last Post: 16th July 2007, 14:26
  4. Problem with regex
    By mikro in forum Newbie
    Replies: 4
    Last Post: 14th December 2006, 10:43
  5. need help with my regex
    By patcito in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2006, 17:39

Tags for this Thread

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.