Boost logo

Boost Users :

From: John Maddock (john_maddock_at_[hidden])
Date: 2003-04-17 10:07:52


> I used regex library which is shipped with boost 1.30 in my project. But
> I found in the case I list below, the regex_match() will crash. Is there
> a pitfall in it?

Yes, it will through an exception if the complexity of the attempted match
grows too high - the alternative is to just keep trying indefinately. You
need to:

1) catch the exception (it's a runtime_error).
2) analyse your regex to reduce ambiguity during matching so that the
matcher spends less time "thrashing" trying to find a match.

John.

> ===================== CODE LIST BEGIN =========================
> #include "stdafx.h"
> #include <afxconv.h>
> #include <boost/regex.hpp>
> using namespace boost;
>
> void do_regex_match(const string& s)
> {
> USES_CONVERSION;
>
> CString _c1,_c2;
> _c1 =
"\\_gl_glcf]a:(D_N~yOA_gg_aeN_o/>jm_gf'0(m_--\\6L_gi_AE_gd5<&0A~_E'_Y-'-,uO7
_so_glTc G_gl_C,_o/*6hC=@_u"; // Failed
> _c2 =
"\\_gl_glcf]a:(D_N~yOA_gg_aeN_o/jm_gf'0(m_--\\6L_gi_AE_gd5<&0A~_E'_Y-'-,uO7_
so_glTc G_gl_C,_o/*6hC=@_u"; // Passed
>
> wstring ws1(L""),ws2(L"");
> ws1=A2W(_c1);
> ws2=A2W(_c2);
>
> wstring wsMatchString(L"");
> wsMatchString=A2W(".*(要)?.*天气.*");
>
> boost::wregex
e(wsMatchString/*,boost::regbase::normal|boost::regbase::icase*/);
> boost::regex_match(ws2,e);// Pass
> boost::regex_match(ws1,e);// Crash
> }
> ======================== CODE LIST END =========================
> As you can see in the code, if any change is made to _c1, the test will
> pass or it will crash. I will list my compiler and system information
> below.
>
> Compiler: Microsoft Visual C++ 6.0 Professionall with SP5
> OS: Microsoft Windows 2000 Professional with SP3
> RAM: 512M
> CPU: PIII 700
>
> Any help will be appreciated.
>
> Phipps Xue
>
> Software Engineer, MCP/MCSD
> Email: xuejm_at_[hidden]
>
>
>
>
>
>
> Info: <http://www.boost.org>
> Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl>
> Unsubscribe: <mailto:boost-users-unsubscribe_at_[hidden]>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


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