Results 1 to 6 of 6

Thread: QRegularExpression question

  1. #1
    Join Date
    Dec 2007
    Location
    Austin, TX
    Posts
    43
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question QRegularExpression question

    I want to match strings using QRegularExpression, but it seems that the RegExp doesn't like the pattern I'm using.

    I have a pattern like "foo \S is a \S", which should match both "foo blah is a bar" and "foo blah is a very big boat" .... but doesn't seem to like either. I tried a simple "the \S" against "the quick fox", that's good... but "the \S fox" doesn't match "the quick fox". Is this an impossible pattern to use?

    Thanks,
    Vycke

  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: QRegularExpression question

    Are you escaping the backslash in your string literal? If not, then your expression is looking for "foo S" literally and not finding it.

  3. #3
    Join Date
    Dec 2007
    Location
    Austin, TX
    Posts
    43
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QRegularExpression question

    I am escaping the S. (trying something, it may be the S is looking for a single char)

  4. #4
    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: QRegularExpression question

    I didn't ask about the S. The compiler will convert the string literal "foo \S" into "foo S" inside the program. If you want the regex to read "foo \S" after the compiler has done its thing then your code should read "foo \\S"

  5. #5
    Join Date
    Dec 2007
    Location
    Austin, TX
    Posts
    43
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QRegularExpression question

    It is. I have been coding for nearly 15 years (yeouch)... this is a question about the QRegularExpression part.

    Vycke

  6. #6
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QRegularExpression question

    The \S in your regex has the meaning any single non-whitespace character. Presumably you mean one or more as in:

    foo \S+ is a \S+

Similar Threads

  1. Question about ftp using Qt
    By lni in forum Qt Programming
    Replies: 11
    Last Post: 19th March 2014, 12:00
  2. Replies: 1
    Last Post: 17th October 2013, 14:30
  3. Some question in example
    By jhowliu in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2013, 16:24
  4. MVC question
    By ^NyAw^ in forum Qt Programming
    Replies: 5
    Last Post: 17th June 2009, 12:11
  5. Question
    By Dumbledore in forum Qt Programming
    Replies: 1
    Last Post: 20th October 2007, 23:12

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.