[Interest] Javascript: regex: no /s flag support?

Alexander Dyagilev alervdvcw at gmail.com
Thu Nov 25 23:55:47 CET 2021


This is C++ code. I know that QRegularExpression does support 's' flag. 
I was asking about javascript...


On 11/26/2021 1:24 AM, ivan tkachenko wrote:
> 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
>
>


More information about the Interest mailing list