PDA

View Full Version : Problem with regex



mikro
13th December 2006, 00:06
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 ;(

e8johan
13th December 2006, 13:40
Perhaps \s is what you are looking for "This matches a whitespace (QChar::isSpace())."

mikro
13th December 2006, 14:33
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^.]

niko
14th December 2006, 08:29
([().+/*-])(name)
if you know the valid variable-names i think you could do it the other way around:


([^a-z0-9\.])(name)

mikro
14th December 2006, 10:43
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.