Results 1 to 5 of 5

Thread: Expression in QRegExp

  1. #1
    Join Date
    May 2009
    Posts
    17
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Expression in QRegExp

    hello,
    I've been trying to understand the meaning of the following expression, but even with QtAssistant and QRegExp documentation, I could'nt get it.

    QRegExp test(QLatin1String("^[a-zA-Z]+\\:.*"));

    What I know:
    the word matched has to start with a sequence of caracters from a to z or A to Z (can I change [a-zA-Z] to \\D instead?)

    from \\: and on, I don't understand.
    this String has to be an Url, I think.

    thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Expression in QRegExp

    QRegExp docs are quite clear IMO. This regexp will match any string composed of :

    • a sequence of one or more letters (basic latin alphabet)
    • a colon ( ':' ) the (double due to C string escaping) backslash prevents this character from having any special meaning (though I don't remember it having one, well it will work anyway...)
    • a sequence of ANY characters of ANY length (zero or more)

    You could of course replace the set by \\D (non-digit class) but it might make more sense to use \\w (word class).

    In a nutshell, this regexp certainly does NOT match URLs. The simplest description is that it matches key:value pairs key being made of latin letters and value of any characters.
    Current Qt projects : QCodeEdit, RotiDeCode

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

    lyucs (28th May 2009)

  4. #3
    Join Date
    May 2009
    Posts
    17
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: Expression in QRegExp

    hum. its weird this doesnt match Urls... anyways, thanks!

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Expression in QRegExp

    It will match URLs (ones with schemas) but only by accident (it will match u bunch of other things as well). If you want an expression for matching URLs then something like this is better:

    Qt Code:
    1. QRegExp("[A-Za-z][A-Za-z0-9]*:\\/\\/.*")
    To copy to clipboard, switch view to plain text mode 

    It will at least make sure there are two slashes behind the colon. And it will allow schemas containing digits. I escaped the slashes themselves "just in case".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    lyucs (28th May 2009)

  7. #5
    Join Date
    May 2009
    Posts
    17
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Expression in QRegExp

    Oh, that will help
    thank you.

Similar Threads

  1. Regular Expression for QDate [YYYY/MM/DD] format
    By bera82 in forum Qt Programming
    Replies: 6
    Last Post: 3rd August 2019, 09:40
  2. QRegExp Help
    By Ahmad in forum Qt Programming
    Replies: 2
    Last Post: 28th May 2007, 00:13
  3. QRegExp lastIndexOf always minimal?
    By skyphyr in forum Qt Programming
    Replies: 3
    Last Post: 12th December 2006, 10:06
  4. need help for my QRegExp
    By patcito in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2006, 16:29
  5. Trouble parsing using simple QRegExp
    By johnny_sparx in forum Qt Programming
    Replies: 4
    Last Post: 24th February 2006, 00:42

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.