0

I had a question, I'm using std::regex with these params :

const std::regex_constants::syntax_option_type grammar = std::regex_constants::ECMAScript;

    const std::regex_constants::syntax_option_type optionNonICase =
            grammar | std::regex_constants::optimize;

    const std::regex_constants::syntax_option_type optionICase =
            std::regex_constants::icase | grammar |
            std::regex_constants::optimize;

I'm parsing a big file line by line (lines are not very big) and extract some data.

I noticed that exact same code with java.util.regex is much faster that std::regex...

Do someone know how to opmtimize regex with STL with ECMA ? Maybe I need to translate to an other grammar like grep, awk ? Otherwise, maybe there is an alternative library to use in c++ ?

Thanks for help

X6Entrepreneur
  • 971
  • 2
  • 10
  • 30
  • `` isn't anything to do with the `STL` which only describes the *containers* and *algorithms* parts of the Standard Library. – Galik May 20 '22 at 16:56
  • If I need faster regex I use `PCRE`. – Galik May 20 '22 at 16:57
  • @Galik -- unfortunately, "STL" has come to mean STandard Library. Despite being a curmudgeon I've given up on fixing that. – Pete Becker May 20 '22 at 17:08
  • @PeteBecker Well, not according to every `C++` reference book I have ever seen. The term refers to a container and algorithms library that is particularly important to computer science and teaching. Therefore, it needs its own name. For that reason I continue to correct people when they get it wrong. – Galik May 20 '22 at 17:39
  • @Galik thanks for your clarification. PCRE exists in Java or C++ ? – X6Entrepreneur May 20 '22 at 17:45
  • @X6Entrepreneur [PCRE](https://www.pcre.org/) is a `C` library, so it works fine with `C++`, but it probably has bindings for other languages too. – Galik May 20 '22 at 17:55
  • @Galik thanks a lot, will take a look. Do you know what's using java.util.regex as grammar ? Because they have a quite good performance, maybe they are using pcre ? It's not possible to use PCRE syntax with STL ? – X6Entrepreneur May 20 '22 at 18:03
  • An instance of the Pattern class represents a regular expression that is specified in string form in a syntax similar to that used by Perl. (from Pattern Java documentation) – X6Entrepreneur May 20 '22 at 18:15
  • 1
    maybe try `Boost.Regex` – Vahagn Avagyan May 20 '22 at 19:45
  • Need documentation on how to build boost for Android with NDK and use it within JNI... Do you have one? – X6Entrepreneur May 20 '22 at 22:27

1 Answers1

0

After some research and some tests, I found that Boost.Regex is way better and way faster than STL Regex. (Like 100x more)

Thanks to this repo : https://github.com/PurpleI2P/Boost-for-Android-Prebuilt I was able to integrate boost quickly and use it on android app with JNI project

X6Entrepreneur
  • 971
  • 2
  • 10
  • 30