1

I am facing a weird problem which is boost::regex_match gives all NULLs results.

Sorry for the bad problem description. Let me copy and paste the code below.

I think the boost lib version should be Boost 1-47-0. GCC 4.3.2 on Linux.

#include <iostream>
#include <string>
#include <boost/regex.hpp>

using namespace std;

int main()
{
    string aFreeText = "26JAN07";
    boost::regex expression("([0-9]{2}[A-Z]{3}[0-9]{2})");
    boost::smatch results;

    if(boost::regex_match(aFreeText, results, expression))
    {
        for(int index=0; index<results.size(); index++)
            DEBUG("YI JI results[" << index << "].str(): " << results[index].str());
    }

    return 0;
}

However, in the log, the display is very weird.

enter image description here

Can anyone kindly help me with this problem? Your kind help will be greatly appreciated.

If the provided information is not enough, please feel free to leave your comment and I will add them later.

jiyi
  • 101
  • 9

1 Answers1

0

Your code works fine with Boost 1.55, GCC 4.9.2 on Windows 7 (64 Bits)

It could be a problem with your boost installation

The code below produces the following result (as you expected)

$ ./re.exe 
Results[0].str(): 26JAN07

C++ code: re.cpp

#include <iostream>
#include <string>
#include <boost/regex.hpp>

using namespace std;

int main()
{
    string aFreeText = "26JAN07";
    boost::regex expression("[0-9]{2}[A-Z]{3}[0-9]{2}");
    boost::smatch results;
    if(boost::regex_match(aFreeText, results, expression))
    {
        for(size_t index=0; index<results.size(); ++index)
        {
            std::cout<<"Results[" << index << "].str(): " << results[index].str()<<std::endl;
        }
    }
    return 0;
}

The CMakeLists.txt used looks like

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
PROJECT(RE)

#############################################################################
SET(Boost_USE_STATIC_LIBS   ON)
SET(Boost_USE_MULTITHREADED OFF)
FIND_PACKAGE(Boost 1.53 COMPONENTS regex REQUIRED)
#############################################################################
IF (NOT(MSVC))
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
ENDIF()

ADD_EXECUTABLE(re re.cpp)
INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(re ${Boost_LIBRARIES})
Guillaume Jacquenot
  • 11,217
  • 6
  • 43
  • 49