Boost logo

Boost Users :

Subject: Re: [Boost-users] Pattern issue with boost::regex
From: Steven Clark (steven.clark_at_[hidden])
Date: 2014-10-23 10:33:20


Strictly speaking, regular expressions do not include back references. Modern regular expression matchers actually implement a superset of the "regular languages". I am fairly sure no extension includes the kind of back reference you are looking for.

Bear in mind that you can construct your regular expression string at runtime. You might consider doing something like the following:

char p[100];
char *sub = "f+\\.";
sprintf(p, "((a b (%s))d d(%s))", sub, sub);

Steven J. Clark
VGo Communications

From: Boost-users [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Tal Shnaiderman
Sent: Thursday, October 23, 2014 4:12 AM
To: boost-users_at_[hidden]
Subject: [Boost-users] Pattern issue with boost::regex

Hi All,

I have a question regarding boost::regex pattern recognition and groups

I created the following code, in it i created a pattern and a string to match:
1
2
3
4
5
6

p = "((a b (f+\\.))d d(\\3)<file:///\\3)>)";
str="a b ffff.d dfff.";

boost::regex pattern(p, boost::regex::icase&boost::regex::extended &~boost::regex::no_bk_refs);
bool match = boost::regex_match(str, pattern);
cout << str << ((match)?"-Pattern is legal":"-Pattern is illegal" )<< endl;

Pattern is illegal

I'm saw that my result is 'Pattern is illegal' because the group \\3<file:///\\3> that refers to (f+\\.) isn't equal to it. if I change the input to

str="a b ffff.d dffff.";

The pattern is legal.

In other words my original plan was to use the \\3<file:///\\3> instead of writing the pattern;

p = "((a b (f+\\.))d d(f+\\.))";

But I can see that in the original pattern it simply expect the same output to reappear

Is there a way I can use the group naming not to copy the (f+\\.) group?

Thanks, I hope my Q is clear since I'm new to the regex topic.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net