Results 1 to 5 of 5

Thread: Negation of QregExp

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2008
    Location
    Poland
    Posts
    80
    Thanks
    4
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Negation of QregExp

    Hello all

    I have a such working expression set on a line edit:
    Qt Code:
    1. locationDirPathValidator.setRegExp(QRegExp("[?<>:*|\"]{0,}"));
    To copy to clipboard, switch view to plain text mode 
    it works well.
    But the point is how to make a negation of such expression?I tried ^(?![?<>:*|\"])$ but it does not work :/
    Could you help me?

  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: Negation of QregExp

    Your initial pattern matches a string consisting of zero or more characters from the list; ?, <, >, :, *, | and "
    By my reckoning the inverse of that would be a non-zero length string that does not contain any of those characters:
    Qt Code:
    1. locationDirPathValidator.setRegExp(QRegExp("[^?<>:*|\"]+"));
    To copy to clipboard, switch view to plain text mode 

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

    MasterBLB (28th November 2012)

  4. #3
    Join Date
    Sep 2008
    Location
    Poland
    Posts
    80
    Thanks
    4
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Negation of QregExp

    Thanks a lot Chris,that's exactly I was needed.
    But please explain me what that + does?I found nothing about it in the Qt Assistant

  5. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Negation of QregExp

    + means 1 or more instances of the previous element.

    Incidentally, it is shorter to use * than {0,} for zero or more ocurrences.

    a* (match zero or more 'a')
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  6. #5
    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: Negation of QregExp

    The +, *, and ? quantifiers are documented in the QRegExp documentation. These symbols are universal in regular expression engine implementations.

Similar Threads

  1. Please help on QRegExp
    By lni in forum Qt Programming
    Replies: 6
    Last Post: 25th September 2011, 07:42
  2. help on qregexp
    By sanqt in forum Newbie
    Replies: 1
    Last Post: 20th February 2011, 16:39
  3. Help on QRegExp please
    By lni in forum Qt Programming
    Replies: 3
    Last Post: 11th August 2010, 06:57
  4. QRegExp
    By tebessum in forum Qt Programming
    Replies: 1
    Last Post: 3rd August 2008, 18:44
  5. QRegExp help
    By Lele in forum Qt Programming
    Replies: 2
    Last Post: 8th February 2008, 10:07

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
  •  
Qt is a trademark of The Qt Company.