Results 1 to 2 of 2

Thread: Partial matching of regex

  1. #1
    Join Date
    May 2007
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Partial matching of regex

    Hello,

    I have a problem I'm trying to find a good solution for and I need some help.
    Let's say I have the regex QRegExp myRegex("x.y[0-5]z"). I also have a string that grows one character at the time.
    What I need to find out is if the string matches the regex, or if not: if it can match in the future, i.e. after adding more characters.

    Basically I want this:
    Qt Code:
    1. canMatch("x", myRegex); // true
    2. canMatch("xy", myRegex); // true
    3. canMatch("xyy", myRegex); // true
    4. canMatch("xyyy", myRegex); // false
    5. canMatch("xyy4", myRegex); // true
    6. canMatch("xyy6", myRegex); // false
    7. canMatch("xyy4z", myRegex); // true
    To copy to clipboard, switch view to plain text mode 
    Does anyone have any ideas? The only regex implementation I have available is QRegExp.
    Last edited by jpn; 28th May 2008 at 20:58. Reason: missing [code] tags

  2. #2
    Join Date
    May 2007
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Partial matching of regex

    *drum roll*

    By using exactMatch(), one can query matchedLength() afterwards and check if that's the same length as the string. Voila!

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.