Newbie to Regex simple test failure...

Hello All, I'm probably missing something obivous here.....So please fogive me if it's a basic error. I am using regex for the first time on MSVC 6 and would like to create a simple function that could pass in a string and an expression to do a regular match on it. I believe I have successfully compiled this library, but I don't understand why either of these simple functions are not working.... bool TestStr (std::string& szExpr, const std::string& szSearch) { bool bResult=false; boost::regex cExpr(szExpr); bResult = boost::regex_match(szSearch, cExpr); return bResult; } or bool TestStr2 (std::string& szExpr, std::string& szSearch) { return boost::regex_match(szSearch, boost::regex(szExpr)); } After debugging these routines, it appears thta the boost::regex declaration fails (at least for the first function) returning a Kernel32.dll exception with some kind of address. The credit card example implies that the search and the regex example I have observed keeps the regex expressions as constansts inside the function, but I would like to be able to parse in my own string Questions? 1. Wht doesn't any of the functions work? 2. Is there a tutorial outside of the regex library I could look at. 3. I would be interested to know if anyone had any POSIX regex examples.... Many thanks in advance, Richard

I'm probably missing something obivous here.....So please fogive me if it's a basic error.
I am using regex for the first time on MSVC 6 and would like to create a simple function that could pass in a string and an expression to do a regular match on it. I believe I have successfully compiled this library, but I don't understand why either of these simple functions are not working....
bool TestStr (std::string& szExpr, const std::string& szSearch) { bool bResult=false;
boost::regex cExpr(szExpr);
bResult = boost::regex_match(szSearch, cExpr);
return bResult; }
or
bool TestStr2 (std::string& szExpr, std::string& szSearch) { return boost::regex_match(szSearch, boost::regex(szExpr)); }
After debugging these routines, it appears thta the boost::regex declaration fails (at least for the first function) returning a Kernel32.dll exception with some kind of address.
The credit card example implies that the search and the regex example I have observed keeps the regex expressions as constansts inside the function, but I would like to be able to parse in my own string
Questions?
1. Wht doesn't any of the functions work?
I would guess there is an exception being thrown somewhere and not getting caught, try: bool TestStr (const std::string& szExpr, const std::string& szSearch) { bool bResult=false; try{ boost::regex cExpr(szExpr); bResult = boost::regex_match(szSearch, cExpr); } catch(const std::exception & e) { std::cout << e.what() << std::endl; } return bResult; } John.

I'm probably missing something obivous here.....So please fogive me if it's a basic error.
I am using regex for the first time on MSVC 6 and would like to create a simple function that could pass in a string and an expression to do a regular match on it. I believe I have successfully compiled this
Hello John, Many thanks for your help and advice here. It helped me to solve my problem, the expression I was passing to the function was not valid. However, I have one more question. I know this is regular expressions here, but why am I not allowed to use "*tart* instead of "(.*)tart(.*)". Regards, Richard "John Maddock" <john@johnmaddock.co.uk> wrote in message news:00e101c43cd0$8496b570$e6df6b51@fuji... library,
but I don't understand why either of these simple functions are not working....
bool TestStr (std::string& szExpr, const std::string& szSearch) { bool bResult=false;
boost::regex cExpr(szExpr);
bResult = boost::regex_match(szSearch, cExpr);
return bResult; }
or
bool TestStr2 (std::string& szExpr, std::string& szSearch) { return boost::regex_match(szSearch, boost::regex(szExpr)); }
After debugging these routines, it appears thta the boost::regex declaration fails (at least for the first function) returning a Kernel32.dll exception with some kind of address.
The credit card example implies that the search and the regex example I have observed keeps the regex expressions as constansts inside the function, but I would like to be able to parse in my own string
Questions?
1. Wht doesn't any of the functions work?
I would guess there is an exception being thrown somewhere and not getting caught, try:
bool TestStr (const std::string& szExpr, const std::string& szSearch) { bool bResult=false; try{ boost::regex cExpr(szExpr); bResult = boost::regex_match(szSearch, cExpr); } catch(const std::exception & e) { std::cout << e.what() << std::endl; } return bResult; }
John.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Many thanks for your help and advice here. It helped me to solve my problem, the expression I was passing to the function was not valid. However, I have one more question. I know this is regular expressions here, but why am I not allowed to use "*tart* instead of "(.*)tart(.*)".
Or you could use .*tart.* Boost regex implements three types of patterns: Perl regular expressions (what you get by default) POSIX extended regular expressions. POSIX basic regular expressions. The latter two are available by passing the appropriate flags to the regex constructor, for example: boost::regex e("\(.*\)abc", boost::regex::basic | boost::regex::icase); Is a case insensitive, POSIX basic expression. In none of three supported grammars is *tart* a valid expression. I assume you were wanting a wildcard for matching filenames? If so that's on my list of things to implement as well, but there are two competing and rather incompatible forms to choose from (Unix style wildcards, and MS-DOS style), which muddies the waters somewhat. John.

Hello John, Many thanks for the information you have provided. I am looking to use wildcards for my program, but not just for file matching. To overcome this I will write a wrapper function to convert * in to .*, but that should not be too difficult. Then I guess it's a case of RTFM for the rest. To solve your problem of wildcarding, may I suggest that you use Unix over DOS or perhaps create a couple of flags to incorprate either. I have noticed somthing else however with the current build. I'm getting C4786 warnings all over the place when I compile. I have tried putting #pragma warning(disable : 4786) at the start of my program, but this appears to have no effect. I wonder if it's something to do with the library. Remember I'm ising mscv6. Regards, Richard "John Maddock" <john@johnmaddock.co.uk> wrote in message news:014b01c43d89$1aec8aa0$307b0252@fuji...
Many thanks for your help and advice here. It helped me to solve my problem, the expression I was passing to the function was not valid. However, I have one more question. I know this is regular expressions here, but why am I not allowed to use "*tart* instead of "(.*)tart(.*)".
Or you could use .*tart.*
Boost regex implements three types of patterns:
Perl regular expressions (what you get by default) POSIX extended regular expressions. POSIX basic regular expressions.
The latter two are available by passing the appropriate flags to the regex constructor, for example:
boost::regex e("\(.*\)abc", boost::regex::basic | boost::regex::icase);
Is a case insensitive, POSIX basic expression.
In none of three supported grammars is *tart* a valid expression.
I assume you were wanting a wildcard for matching filenames? If so that's on my list of things to implement as well, but there are two competing and rather incompatible forms to choose from (Unix style wildcards, and MS-DOS style), which muddies the waters somewhat.
John.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Many thanks for the information you have provided. I am looking to use wildcards for my program, but not just for file matching. To overcome this I will write a wrapper function to convert * in to .*, but that should not be too difficult. Then I guess it's a case of RTFM for the rest. To solve your problem of wildcarding, may I suggest that you use Unix over DOS or perhaps create a couple of flags to incorprate either.
Yep, in case it helps, here's a regular expression and format string I've used in the past to convert a DOS-style wildcard to a Perl regex: static const boost::regex transformer("([+{}()\\[\\]$\\^|])|(\\*)|(\\?)|(\\.)|([\\\\/:])"); static const char* replace_string = "(?1\\\\$1)(?2[^\\\\\\\\/\\:]*)(?3[^\\\\\\\\/\\:])(?4\\(\\?\\:\\\\.|$\\))(?5 [\\\\\\\\\\\\/\\:])";
I have noticed somthing else however with the current build. I'm getting C4786 warnings all over the place when I compile. I have tried putting #pragma warning(disable : 4786) at the start of my program, but this appears to have no effect. I wonder if it's something to do with the library. Remember I'm ising mscv6.
Well if you insist on using a broken compiler that's what you'll have to expect, I've tried really hard to suppress those warnings myself, but they never seem to stay turned off :-( In short use VC7.1 instead... John.

"John Maddock" <john@johnmaddock.co.uk> wrote in message news:010c01c43f1d$0c56e7c0$19ef0352@fuji... [snip]
I have noticed somthing else however with the current build. I'm
getting
C4786 warnings all over the place when I compile. I have tried putting #pragma warning(disable : 4786) at the start of my program, but this appears to have no effect. I wonder if it's something to do with the library. Remember I'm ising mscv6.
Well if you insist on using a broken compiler that's what you'll have to expect, I've tried really hard to suppress those warnings myself, but they never seem to stay turned off :-(
Since this is specific to msvc6 you can circumvent these warnings by placing the following in your stdafx.h. This assumes that you are using a stdafx.h, of course. All of the container includes may not be required, but this works for me, and speeds up compilations since I'm using precompiled headers. #pragma warning( disable : 4786 ) #include <yvals.h> #pragma warning( disable : 4786 ) #include <new> #pragma warning( disable : 4786 ) #include <map> #pragma warning( disable : 4786 ) #include <set> #pragma warning( disable : 4786 ) #include <vector> #pragma warning( disable : 4786 ) #include <list> #pragma warning( disable : 4786 ) Jeff Flinn

Seems like overkill, I only ever needed ONE #pragma warning( disable : 4786 ) to get rid of all of them At Friday 2004-05-21 05:04, you wrote:
"John Maddock" <john@johnmaddock.co.uk> wrote in message news:010c01c43f1d$0c56e7c0$19ef0352@fuji...
[snip]
I have noticed somthing else however with the current build. I'm
getting
C4786 warnings all over the place when I compile. I have tried putting #pragma warning(disable : 4786) at the start of my program, but this appears to have no effect. I wonder if it's something to do with the library. Remember I'm ising mscv6.
Well if you insist on using a broken compiler that's what you'll have to expect, I've tried really hard to suppress those warnings myself, but they never seem to stay turned off :-(
Since this is specific to msvc6 you can circumvent these warnings by placing the following in your stdafx.h. This assumes that you are using a stdafx.h, of course. All of the container includes may not be required, but this works for me, and speeds up compilations since I'm using precompiled headers.
#pragma warning( disable : 4786 ) #include <yvals.h> #pragma warning( disable : 4786 ) #include <new> #pragma warning( disable : 4786 ) #include <map> #pragma warning( disable : 4786 ) #include <set> #pragma warning( disable : 4786 ) #include <vector> #pragma warning( disable : 4786 ) #include <list> #pragma warning( disable : 4786 )
Jeff Flinn
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Victor A. Wagner Jr. http://rudbek.com The five most dangerous words in the English language: "There oughta be a law"
participants (4)
-
Jeff Flinn
-
John Maddock
-
Richard Latter
-
Victor A. Wagner Jr.