[Interest] Javascript: regex: no /s flag support?
ivan tkachenko
me at ratijas.tk
Thu Nov 25 23:24:29 CET 2021
Hi,
On Thursday, November 25, 2021 11:47:19 PM MSK Alexander Dyagilev wrote:
> I'm trying to:
>
> var re = new RegExp('someregex', 's');
>
> Getting error: SyntaxError: Invalid flags supplied to RegExp constructor.
At least in qtbase/src/corelib/text/qregularexpression.h[1] file there is a
QRegularExpression::DotMatchesEverythingOption enum constant. Which means it's
just a matter of checking for QV4 engine implementation of those flags. Here's
what in qv4regexp{_p.h,cpp} files[2][3], either in the struct RegExp : Base {}
declaration, or in flagsAsString() method:
bool global() const;
bool ignoreCase() const;
bool multiLine() const;
bool unicode() const;
bool sticky() const;
(little bit stripped down for convenience of the reader)
QString result;
if (flags & RegExp_Global)
result += 'g';
if (flags & RegExp_IgnoreCase)
result += 'i';
if (flags & RegExp_Multiline)
result += 'm';
if (flags & RegExp_Unicode)
result += 'u';
if (flags & RegExp_Sticky)
result += 'y';
return result;
If we compare that to the MDN docs[4], we can see that exactly two out of
seven flags are missing.
> Can anything be done for '.' to match _any_ character?
Not practically, no. But you can contribute upstream, or in the meantime
create your own wrapper class in C++ that would #include Qt's private headers
or something.
[1]: https://code.woboq.org/qt5/qtbase/src/corelib/text/
qregularexpression.h.html#QRegularExpression::DotMatchesEverythingOption
[2]: https://code.woboq.org/qt5/qtdeclarative/src/qml/jsruntime/
qv4regexp_p.h.html
[3]: https://code.woboq.org/qt5/qtdeclarative/src/qml/jsruntime/
qv4regexp.cpp.html
[4]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/
Regular_Expressions#advanced_searching_with_flags
--
ivan (@ratijas)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20211126/45cc3e96/attachment.sig>
More information about the Interest
mailing list