From c800214e6d6d1242640a3d140fc410caf19a0dc2 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Fri, 16 Oct 2015 16:15:39 -0300 Subject: [PATCH] Fix pcre_exec matched string --- src/operators/rx.cc | 3 +-- src/utils/regex.cc | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/operators/rx.cc b/src/operators/rx.cc index ebfe265f..710c8e37 100644 --- a/src/operators/rx.cc +++ b/src/operators/rx.cc @@ -30,8 +30,7 @@ bool Rx::evaluate(Assay *assay, const std::string& input) { SMatch match; if (regex_search(input, &match, *m_re) && match.size() >= 1) { - std::cout << "wheee" << std::endl; - // this->matched.push_back(match.match); + this->matched.push_back(match.match); return true; } diff --git a/src/utils/regex.cc b/src/utils/regex.cc index 9437c74a..1bc1987f 100644 --- a/src/utils/regex.cc +++ b/src/utils/regex.cc @@ -48,8 +48,15 @@ Regex::Regex(const std::string& pattern_) int regex_search(const std::string& s, SMatch *match, const Regex& regex) { int ovector[OVECCOUNT]; - return pcre_exec(regex.m_pc, regex.m_pce, s.c_str(), + int ret = pcre_exec(regex.m_pc, regex.m_pce, s.c_str(), s.size(), 0, 0, ovector, OVECCOUNT) > 0; + + if (ret > 0) { + match->match = std::string(s, ovector[2], ovector[3] - ovector[2]); + match->size_ = ret; + } + + return ret; } int regex_search(const std::string& s, const Regex& regex) {