What is \o in QRegExp and how to port it to QRegularExpression?
-
I can't find it in any PCRE documentation. Here was my
QregExpthat was working fine:
"\\b0\\o*[89]\\d*\\b"
If I simply change it toQRegularExpression- it is invalid and the error is "missing opening brace after \o".It's supposed to match numeric literals in the text, including fractional numbers, and if I remove the
\\o*[89]part it no longer matches the point and anything to the right of it.Please help.
-
I can't find it in any PCRE documentation. Here was my
QregExpthat was working fine:
"\\b0\\o*[89]\\d*\\b"
If I simply change it toQRegularExpression- it is invalid and the error is "missing opening brace after \o".It's supposed to match numeric literals in the text, including fractional numbers, and if I remove the
\\o*[89]part it no longer matches the point and anything to the right of it.Please help.
@Violet-Giraffe
As you can see from e.g. https://doc.qt.io/qt-5/qregexp.html#details there was never any\ocharacter match inQRegExp. So goodness knows what it did or was supposed to do.Don't know whether you even verified it worked. I would start out by discovering just exactly what it did match. "numeric literals in the text, including fractional numbers" is rather vague. Positive/negative leading sign?
.vs,for decimal point, bearing in mind locale? Leading digit required before this, or can be omitted? Locale-aware thousands-separator of any kind allowed or not? Why8or9optionally followed by further digits? Why would that come after "numeric literals in the text, including fractional numbers", and it seems this "fractional number" must be preceded by a0?When you have decided what rules you want here you are then ready to write it as a
QRegularExpression. -
@Violet-Giraffe
As you can see from e.g. https://doc.qt.io/qt-5/qregexp.html#details there was never any\ocharacter match inQRegExp. So goodness knows what it did or was supposed to do.Don't know whether you even verified it worked. I would start out by discovering just exactly what it did match. "numeric literals in the text, including fractional numbers" is rather vague. Positive/negative leading sign?
.vs,for decimal point, bearing in mind locale? Leading digit required before this, or can be omitted? Locale-aware thousands-separator of any kind allowed or not? Why8or9optionally followed by further digits? Why would that come after "numeric literals in the text, including fractional numbers", and it seems this "fractional number" must be preceded by a0?When you have decided what rules you want here you are then ready to write it as a
QRegularExpression.@JonB
Thanks, good to know it really is an obscure regex directive and I didn't just fail at googling. As you can see,QRegularExpressiondoes handle it in some way, as there is a special check and error message for it.
I think it means an octal number, and the [89] part allows it to match regular base 10 literals, except they still have to start with '0'? This really is weird, I'll just scrap it and rewrite from scratch as you suggested.P. S. I have just discovered the true purpose of ChatGPT. It must be the only entity in the world that can both write and explain regexes. Don't trust it blindly and double-check everything, but it's great help.
-
V Violet Giraffe has marked this topic as solved on
-
@JonB
Thanks, good to know it really is an obscure regex directive and I didn't just fail at googling. As you can see,QRegularExpressiondoes handle it in some way, as there is a special check and error message for it.
I think it means an octal number, and the [89] part allows it to match regular base 10 literals, except they still have to start with '0'? This really is weird, I'll just scrap it and rewrite from scratch as you suggested.P. S. I have just discovered the true purpose of ChatGPT. It must be the only entity in the world that can both write and explain regexes. Don't trust it blindly and double-check everything, but it's great help.
@Violet-Giraffe
Let's assumeQRegExpaccepted\oas meaning "octal digit". Then we could rewrite it as"\\b0[0-7]*[89]\\d*\\b"This would still be pretty odd!
- Word boundary.
- Literal 0.
- Optional zero or more digits in range 0--7. [So far so good.]
- Mandatory terminated by one of either an 8 or a 9. [Why?]
- Optionally followed by zero or more digits in range 0--9. [Why?]
- Word boundary.
There is probably something there about accepting octal digits because when you write an octal number literally in C/C++ source code (may also be accepted by e.g.
scanf()) you do start it with a leading0, e.g.012is octal for decimal 10. But the rest of its requirements don't make sense to me. -
@Violet-Giraffe
Let's assumeQRegExpaccepted\oas meaning "octal digit". Then we could rewrite it as"\\b0[0-7]*[89]\\d*\\b"This would still be pretty odd!
- Word boundary.
- Literal 0.
- Optional zero or more digits in range 0--7. [So far so good.]
- Mandatory terminated by one of either an 8 or a 9. [Why?]
- Optionally followed by zero or more digits in range 0--9. [Why?]
- Word boundary.
There is probably something there about accepting octal digits because when you write an octal number literally in C/C++ source code (may also be accepted by e.g.
scanf()) you do start it with a leading0, e.g.012is octal for decimal 10. But the rest of its requirements don't make sense to me.Thanks for disassembling and explaining that for me. I still don't understand what it did, and I definitely don't want it in my codebase now that I see how weird it is.