Results 1 to 5 of 5

Thread: Problem with regex

  1. #1
    Join Date
    Apr 2006
    Location
    Erlangen, Germany
    Posts
    58
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem with regex

    hi all,
    i need to search for complete words. the problem is, that sometimes they contain a . - in this case of course i need to find only those where i was searching for the complete word including the dot, not those where i was searching for only the part after the dot.
    Example:
    schachtunten.laenge
    if i search for "laenge" i must not find this, only if i really search for schachtunten.laenge
    i would have liked to search for \bpattern\b but \b includes .
    is there a way to search for "boundary but not a dot"? Everything i tried didn't seem to work ;(

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with regex

    Perhaps \s is what you are looking for "This matches a whitespace (QChar::isSpace())."

  3. #3
    Join Date
    Apr 2006
    Location
    Erlangen, Germany
    Posts
    58
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with regex

    no, unfortunately it is not that easy. i am actually using this within formulas. i have a formula like
    length * width
    i use the regexes to replace the variablenames in there with the correct values like
    3 * 2
    and then use some code i found in the speedcrunch-code to calculate a result.
    now unfortunately sometimes something does not only have its own attributes but needs to use the attributes of some connected assets. Think for example of a sewage water system where you have pipes and manholes. now you have 3 assets: 2 manholes and one pipe. If you want to know the volume of earth that you need to remove before building the pipe you have to calculate:
    length * (manhole1.depth * manhole2.depth)/2
    So this is why there are dots in there
    therefore i will not always have a blank around the word i am searching for, there might also be brackets or other stuff. So i could possibly search for
    ([().+/*-])(name)
    but i would have to check this everytime i allow a different mathematical expression. It would be more elegant if there was something like [\b^.]

  4. #4
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with regex

    ([().+/*-])(name)
    if you know the valid variable-names i think you could do it the other way around:
    Qt Code:
    1. ([^a-z0-9\.])(name)
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to niko for this useful post:

    mikro (14th December 2006)

  6. #5
    Join Date
    Apr 2006
    Location
    Erlangen, Germany
    Posts
    58
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with regex

    good thinking, thank you. of course that should work much easier. i just hope, that i will be able to replace just the second found part (which is the beauty of the \b: they don't count as a found character) but at least i know a decent way to solve this.

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.