-3

Hello this is my string

last_name, first_name
bjorge, philip
kardashian, kim
mercury, freddie

in php i am using preg_match_all (pcre) to start regex process

preg_match_all("/(.*), (.*)/", $input_lines, $output_array);

now i installed pcre on c++ and i want to know what exactly process in c++ pcre that equal my php code? what exactly function in c++ pcre that work like php preg_match_all ?

MyJustWorking
  • 117
  • 2
  • 8
  • 1
    The instructions are here: http://www.pcre.org/pcre.txt look at the bottom under `pcrecpp` for the `C++` API. – Galik Apr 12 '16 at 05:49

1 Answers1

0

In C++ 11 regular expressions are supported by standard library. So you don't need to use pcre without any specific reasons.

As for example above, you can achieve the same using standard regular expressions. E.g.:

#include <iostream>
#include <string>
#include <regex>

int main()
{
  std::vector<std::string> input = {
    "last_name, first_name",
    "bjorge, philip",
    "kardashian, kim",
    "mercury, freddie"
  };

  std::regex re("(.*), (.*)");
  std::smatch pieces;

  for (const std::string &s : input) {
    if (std::regex_match(s, pieces, re)) {
      std::cout << "Pieces: " << pieces.size() << std::endl;
      for (size_t i = 0; i < pieces.size(); ++i) {
        std::cout << pieces[i].str() << std::endl;
      }
    }
  }

  return 0;
}
Vadim Key
  • 1,242
  • 6
  • 15
  • i know it and i try it. but i think pcre is faster and i want to use it. im already use default regex .... – MyJustWorking Apr 12 '16 at 06:27
  • Just curious, how much is faster? – Vadim Key Apr 12 '16 at 06:53
  • So much faster that I want to write my project with (on heavy process) – MyJustWorking Apr 12 '16 at 06:55
  • Yep, found this link http://www.boost.org/doc/libs/1_60_0/libs/regex/doc/html/boost_regex/background_information/performance/section_Testing_Perl_searches_platform_linux_compiler_GNU_C_version_5_1_0_.html std::regex still have to be improved :) – Vadim Key Apr 12 '16 at 07:04