I tried to use the regex library in c++11 on OSX using clang:
// product format
// "AAPL 150918C00099500"
// python regex
// "(?P<Symbol>[a-zA-Z0-9]+)\s*(?P<Expiry>\d{6})(?P<Payoff>[C|P])(?P<Strike>\d{8})"
#include <string>
#include <regex>
#include <iostream>
void parseProductString()
{
std::string s{ "AAPL 150918C00099500" };
std::regex pat{ R"([a-zA-Z0-9]{1,6})\s*(\d{6})([CP]{1})(\d{8})" };
bool isMatch = std::regex_match( s, pat );
std::sregex_iterator it( s.begin(), s.end(), pat );
for( ; it != std::sregex_iterator{}; ++it )
{
std::cout << ( *it )[0] << std::endl;
}
}
The output of the code below should be:
AAPL
150918
C
00099500
Instead it spits out
AAPL
150918
C00099
500
This seems like a bug... Does anybody know of a way around this ?
Thanks
System details:
$ uname -a
Darwin MBP.fios-router.home 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64 i386 MacBookPro11,2 Darwin
$ g++ --version
Configured with: --prefix=/Applications/http://ift.tt/1d5DwEL --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
Aucun commentaire:
Enregistrer un commentaire