Overview
Features
Download
Documentation
Community
Add-Ons & Services

RegularExpression issue

Please post support and help requests here.

RegularExpression issue

Postby Sylva1n » 14 Dec 2012, 23:37

Hello,

I tried to compile the RegularExpression example from http://pocoproject.org/slides/040-StringsAndFormatting.pdf.

#include "Poco/RegularExpression.h"
#include <vector>

#include <iostream>


using Poco::RegularExpression;
int main(int argc, char** argv)
{

RegularExpression re2("([0-9]+) ([0-9]+)");
RegularExpression::MatchVec posVec;
re2.match("123 456", 0, posVec);
// posVec[0].offset == 0, posVec[0].length == 7
// posVec[1].offset == 0, posVec[1].length == 3
// posVec[2].offset == 4, posVec[2].length == 3

std::vector<std::string> vec;
re2.split("123 456", 0, vec);
// vec[0] == "123"
// vec[1] == "456"

std::cout << "vec[0]: " + vec[0] << std::endl;
std::cout << "vec[1]: " + vec[1] << std::endl;


return 0;
}



The stdout displays:
vec[0]
Segmentation fault (core dumped)

Process returned 139 (0x8B)


What is the matter?

Thanks,

Sylvain
Sylva1n
 
Posts: 4
Joined: 12 Dec 2012, 23:56

Re: RegularExpression issue

Postby alex » 20 Dec 2012, 03:48

Sylva1n wrote:What is the matter?

Works for me:

Code: Select all
RegularExpression re2("([0-9]+) ([0-9]+)");
RegularExpression::MatchVec posVec;
re2.match("123 456", 0, posVec);

assert(posVec[0].offset == 0);
assert(posVec[0].length == 7);
assert(posVec[1].offset == 0);
assert(posVec[1].length == 3);
assert(posVec[2].offset == 4);
assert(posVec[2].length == 3);

std::vector<std::string> vec;
re2.split("123 456", 0, vec);

std::cout << "vec[0]: " << vec[0] << std::endl;
std::cout << "vec[1]: " << vec[1] << std::endl;
std::cout << "vec[2]: " << vec[2] << std::endl;

output wrote:vec[0]: 123 456
vec[1]: 123
vec[2]: 456
alex
 
Posts: 1146
Joined: 11 Jul 2006, 16:27
Location: United_States


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest