473,326 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Unexpected results in matching a regex

#define BOOST_REGEX_DYN_LINK

#include <iostream>
#include <boost\regex.hpp>

using namespace boost;
using namespace std;

int main()
{
regex reg_exp("\xF8.\x2A..\x0D(P|V)[0-9A-F]{3}");

// I would expect this to match, and it does.
cout << regex_match("\xF8p\x2Aqf\x0DPFFF", reg_exp) << endl;

// I would expect this to *not* match due to the 'w'.
// Why does it match?
cout << regex_match("\xF8p\x2Aqfw\x0DPFFF", reg_exp) << endl;
}
Feb 8 '06 #1
5 2118
Dave wrote:
#define BOOST_REGEX_DYN_LINK

#include <iostream>
#include <boost\regex.hpp>
Should change it to

#include <boost/regex.hpp>

and _never_ again use backslashes in the header name.

using namespace boost;
using namespace std;

int main()
{
regex reg_exp("\xF8.\x2A..\x0D(P|V)[0-9A-F]{3}");

// I would expect this to match, and it does.
cout << regex_match("\xF8p\x2Aqf\x0DPFFF", reg_exp) << endl;

// I would expect this to *not* match due to the 'w'.
// Why does it match?
cout << regex_match("\xF8p\x2Aqfw\x0DPFFF", reg_exp) << endl;
}


Oh, did you try Boost online forum? What did they say?

V
--
Please remove capital As from my address when replying by mail
Feb 8 '06 #2

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:_U***************@newsread1.mlpsca01.us.to.ve rio.net...
Dave wrote:
#define BOOST_REGEX_DYN_LINK

#include <iostream>
#include <boost\regex.hpp>


Should change it to

#include <boost/regex.hpp>

and _never_ again use backslashes in the header name.

using namespace boost;
using namespace std;

int main()
{
regex reg_exp("\xF8.\x2A..\x0D(P|V)[0-9A-F]{3}");

// I would expect this to match, and it does.
cout << regex_match("\xF8p\x2Aqf\x0DPFFF", reg_exp) << endl;

// I would expect this to *not* match due to the 'w'.
// Why does it match?
cout << regex_match("\xF8p\x2Aqfw\x0DPFFF", reg_exp) << endl;
}


Oh, did you try Boost online forum? What did they say?

V
--
Please remove capital As from my address when replying by mail


Actually, yes I did post to Boost, but my message has not yet appeared. Your
comment on backslashes contributes absolutely nothing to this thread.
Feb 8 '06 #3
"Dave" <be***********@yahoo.com> wrote in news:11uk61b2s8goc61
@news.supernews.com:
#define BOOST_REGEX_DYN_LINK

#include <iostream>
#include <boost\regex.hpp>

using namespace boost;
using namespace std;

int main()
{
regex reg_exp("\xF8.\x2A..\x0D(P|V)[0-9A-F]{3}");

// I would expect this to match, and it does.
cout << regex_match("\xF8p\x2Aqf\x0DPFFF", reg_exp) << endl;

// I would expect this to *not* match due to the 'w'.
// Why does it match?
cout << regex_match("\xF8p\x2Aqfw\x0DPFFF", reg_exp) << endl;
}


You're asking in the wrong place.... that's not Standard C++. You'll be
much better off asking in the boost user's mailing lists and such.
Feb 8 '06 #4
Dave wrote:
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:_U***************@newsread1.mlpsca01.us.to.ve rio.net...
Dave wrote:
#define BOOST_REGEX_DYN_LINK

#include <iostream>
#include <boost\regex.hpp>
Should change it to

#include <boost/regex.hpp>

and _never_ again use backslashes in the header name.

using namespace boost;
using namespace std;

int main()
{
regex reg_exp("\xF8.\x2A..\x0D(P|V)[0-9A-F]{3}");

// I would expect this to match, and it does.
cout << regex_match("\xF8p\x2Aqf\x0DPFFF", reg_exp) << endl;

// I would expect this to *not* match due to the 'w'.
// Why does it match?
cout << regex_match("\xF8p\x2Aqfw\x0DPFFF", reg_exp) << endl;
}


Oh, did you try Boost online forum? What did they say?

V
--
Please remove capital As from my address when replying by mail

Actually, yes I did post to Boost, but my message has not yet appeared.


So, you're growing impatient, is that it? Generally, Boost functionality
is OT here. If you asked about std::tr1, you'd be closer to the topic of
this newsgroup.

Have you tried other tools, like Perl or 'sed' to see if the expression is
a match? No, I didn't. I just think that "\x2Aqfw" is not a match for
"\x2A..". You probably wanted to add another dot there.
Your
comment on backslashes contributes absolutely nothing to this thread.


Not true, it promotes healthy coding practices and that is always
a GOOD THING(tm).

V
--
Please remove capital As from my address when replying by mail
Feb 8 '06 #5
Dave wrote:

int main()
{
regex reg_exp("\xF8.\x2A..\x0D(P|V)[0-9A-F]{3}");

// I would expect this to match, and it does.
cout << regex_match("\xF8p\x2Aqf\x0DPFFF", reg_exp) << endl;

// I would expect this to *not* match due to the 'w'.
// Why does it match?
cout << regex_match("\xF8p\x2Aqfw\x0DPFFF", reg_exp) << endl;
}


I can't speak for the Boost implementation, but our TR1 implementation
gets the same result. It's a little clearer with a slight rewriting of
the regular expression. Yours was:

regex reg_exp("\xF8.\x2A..\x0D(P|V)[0-9A-F]{3}");

In the ASCII encoding that's equivalent to:

regex reg_exp("\xF8.*..\x0D(P|V)[0-9A-F]{3}");
And that embedded ".*.." will eat up two or more characters.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Feb 8 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images...
3
by: Day Of The Eagle | last post by:
Jeff_Relf wrote: > ...yet you don't even know what RegEx is. > I'm looking at the source code for mono's Regex implementation right now. You can download that source here ( use the class...
13
by: Nigel J. Andrews | last post by:
This will be a little vague, it was last night and I can't now do the test in that db (see below) so can't give the exact wording. I seem to remember a report a little while ago about tsearch v2...
9
by: Martijn | last post by:
Hi, Which is the prevalent way of matching a filename to a mask in runtime? The best I can think of, is sscanf. Thanks for the help! <OT> It's for the Windows platform, so any functions...
7
by: Kevin CH | last post by:
Hi, I'm currently running into a confusion on regex and hopefully you guys can clear it up for me. Suppose I have a regular expression (0|(1(01*0)*1))* and two test strings: 110_1011101_ and...
8
by: Xah Lee | last post by:
the Python regex documentation is available at: http://xahlee.org/perl-python/python_re-write/lib/module-re.html Note that, i've just made the terms of use clear. Also, can anyone answer what...
0
by: Tidane | last post by:
Visual Basic.NET Framework 2.0 I've created a program to parse out text as the program recieved it and use Regex matching to decide what should be done. My problem is that the text is matching when...
6
by: Gary Wardell | last post by:
Hi, I wanted to check if this was correct be behavior before reporting it as a bug in FireFox. Given this function: function test() { var re;
1
by: Joe Strout | last post by:
Wow, this was harder than I thought (at least for a rusty Pythoneer like myself). Here's my stab at an implementation. Remember, the goal is to add a "match" method to Template which works like...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.