Funny QRegExp whitespace behavior
While trying to eliminate empty HTML paragraphs I’ve run into some strange behavior while using a regular expression on a QString using the replace function. The intent is to replace
example 1:
- <p attributes> </p>
or
example 2:
- <p attributes>
- </p>
with a null value (”“). Example 2 differs from example 1 only by the addition of newlines. If A is a QString then the expression
fails while the explicitly listing the whitespace elements (including a space character) works just fine
Does anyone know why QRegExp fails to detect whitespace properly in a QString?
2 replies
Tannin
Thanks for the pointer. After reading your reply I found the note in the QRegExp documentation that tells me to use double backslashes. I tried it and it works with both QRegExp expresions. My compiler didn’t give me a warning. I’m using Qt Creator 2.4.0 with the standard supplied compiler.
After some additional testing it became clear that \s was being interpreted as the character s but that both \n and \\n was being interpreted as a newline character (not sure why both works).
You must log in to post a reply. Not a member yet? Register here!
