Unsolved Qt regex modifier
-
I'm trying to use a regex that uses
\u
modifier:(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))
It would match strings like
.com
, the tld of an url, but when I callisValid()
it returns false and when running I got this warning:QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object
Is there a solution? What can I be doing in order to solve this?
-
@yodusow-bardon said:
Hi
I wonder if
QRegularExpression::UseUnicodePropertiesOption 0x0040
http://doc.qt.io/qt-5/qregularexpression.html
is what you are after? -
@mrjj I tried it too and it doesn't work. I my case I tried - it would match anything, including unicode characters:
[a-z\u00a1-\uffff0-9]*
And when calling
isValid
it returns false along with the same warning, even usingUseUnicodePropertiesOption
. -
@Minupi said:
hmm looking in
qregularexpression.cpp
I only see
QT_TRANSLATE_NOOP("QRegularExpression", "PCRE does not support \L, \l, \N{name}, \U, or \u"),but at same time docs says "It fully supports Unicode"
Does it work if u put the unicode directly in the string ?
-
@mrjj I might, but the thing is that I need to use
\u
as it has a range:\uffff0-9
.I think that I'm going to drop the
QRegularExpression
and useQRegExp
instead. -
@Minupi said:
Well if it just accepts a \u I agree it seems more sensible than to figure out how to do \u like with QRegularExpression. -
@mrjj It's kinda nonsense as
QRegularExpresion
came to be better thanQRegExp
, but anyway, let's stick with it as it's the only option left here.Thank you.
-
@yodusow-bardon said:
btw
did u try
\x{FFFF} -
@mrjj Yes, I did and I got an error saying:
hex constants must have at least one hex digit
-
@mrjj I fixed it, and it's working now... You just have to escape the
\x
, like\\x
, for instance:[a-z\\x{00a1}-\\x{ffff}0-9]*
. -
@Minupi
Oh yes always escape "\"
Super- :) -
@mrjj Thank you, helped a lot. I realised that
QRegularExpression
is using the same syntax as PHP. -
@Minupi
Good to hear. :)
It says its perl syntax but maybe PHP uses perl style or reverse? -
@mrjj Yes, it resembles perl style, it's called PCRE.
-
Hi,
To help you with your regular expression development, you can use the regular expression tool. It's available starting with Qt 5.6