std regex_search to match only current line

前端 未结 2 1679
Happy的楠姐
Happy的楠姐 2021-01-24 16:49

I use a various regexes to parse a C source file, line by line. First i read all the content of file in a string:

ifstream file_stream(\"commented.cpp\",ifstream         


        
2条回答
  •  囚心锁ツ
    2021-01-24 17:25

    If it is not what you want please comment so I will delete the answer

    What you are doing is not a correct way of using a regex library.
    Thus here is my suggestion for anyone that wants to use std::regex library.

    1. It only supports ECMAScript that somehow is a little poor than all modern regex library.
    2. It has bugs as many as you like ( just I found ):

      1. the same regex but different results on Linux and Windows only C++
      2. std::regex and ignoring flags
      3. std::regex_match and lazy quantifier with strange behavior
    3. In some cases (I test specifically with std::match_results ) It is 200 times slower in comparison to std.regex in d language

    4. It has very confusing flag-match and almost it does not work (at least for me)

    conclusion: do not use it at all.


    But if anyone still demands to use c++ anyway then you can:

    1. use boost::regex about Boost library because:

      1. It is PCRE support
      2. It has less bug ( I have not seen any )
      3. It is smaller in bin file ( I mean executable file after compiling )
      4. It is faster then std::regex
    2. use gcc version 7.1.0 and NOT below. The last bug I found is in version 6.3.0

    3. use clang version 3 or above

    If you have enticed (= persuade) to NOT use c++ then you can use:

    1. Use d regular expression link library for large task: std.regex and why:

      1. Fast Faster Command Line Tools in D
      2. Easy
      3. Flexible drn
    2. Use native pcre or pcre2 link that have been written in c

      • Extremely fast but a little complicated
    3. Use perl for a simple task and specially Perl one-liner link

提交回复
热议问题