QString: replace white space behind "</tr>"
sonichy last edited by sonichy
I want a HTML indent function in QTextEdit.
Replace white space:
s = s.replace(QRegExp("[\\s]+"), "")
I want something like:
s = s.replace("</tr>white space", "</tr>\n")
KillerSmath last edited by
You must to scape the slash caracter
\\/in regular expression. Further you can use
\\1to insert the first captured group
(</tr>)on replaced string.
See an example:
sonichy last edited by
@KillerSmath Worked out, it is should be like these:
s = s.replace(QRegExp("[\\s]+(<td>)"), "\\1"); // delete white space before <td> s = s.replace(QRegExp("[\\s]+(</td>)"), "\\1"); // delete white space before </td> s = s.replace(QRegExp("(</tr>)[\\s]+"), "\\1\n"); // delete white space after </tr>
JonB last edited by
Your answer is useful to the rest of the world, but for anyone reading this you have erroneously inserted a
/tr, which should be removed.
KillerSmath last edited by KillerSmath
Sorry but i used
\\to escape a backward slash to string because
/in means "start or end of a regular expression" and it needs to be escaped.
JonB last edited by JonB
I've used regular expressions in various languages for hundreds of years, and I've never escaped a
/. Nor has
/ever meant "start of regular expression" as per your sources! So I'm looking into this mystery (for me) now...!
I'm lost. This is all to do with "using
/, that's not part of regular expressions. I think that's only because they are for using JS
string.replace(/.../)"regular expression literal" syntax, no? Why would that apply to
fcarney last edited by
Or you could use the new C++ 11 literals:
No idea what they were smoking on the delimeter( version.
@KillerSmath what tools are you using for regular expressions ?
If you take VI for example, / are used to separate elements when doing a search and replace for example. Same with the sed command. With sed you can change the separation char if you need to use / in an expression.