Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / regex / doc / html / boost_regex / background_information / faq.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>FAQ</title>
5 <link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../index.html" title="Boost.Regex 5.1.3">
8 <link rel="up" href="../background_information.html" title="Background Information">
9 <link rel="prev" href="futher.html" title="References and Further Information">
10 <link rel="next" href="performance.html" title="Performance">
11 </head>
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../more/index.htm">More</a></td>
20 </tr></table>
21 <hr>
22 <div class="spirit-nav">
23 <a accesskey="p" href="futher.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../background_information.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="performance.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="section">
26 <div class="titlepage"><div><div><h3 class="title">
27 <a name="boost_regex.background_information.faq"></a><a class="link" href="faq.html" title="FAQ">FAQ</a>
28 </h3></div></div></div>
29 <p>
30         <span class="bold"><strong>Q.</strong></span> I can't get regex++ to work with escape
31         characters, what's going on?
32       </p>
33 <p>
34         <span class="bold"><strong>A.</strong></span> If you embed regular expressions in C++
35         code, then remember that escape characters are processed twice: once by the
36         C++ compiler, and once by the Boost.Regex expression compiler, so to pass
37         the regular expression \d+ to Boost.Regex, you need to embed "\d+"
38         in your code. Likewise to match a literal backslash you will need to embed
39         "\\" in your code.
40       </p>
41 <p>
42         <span class="bold"><strong>Q.</strong></span> No matter what I do regex_match always
43         returns false, what's going on?
44       </p>
45 <p>
46         <span class="bold"><strong>A.</strong></span> The algorithm regex_match only succeeds
47         if the expression matches <span class="bold"><strong>all</strong></span> of the text,
48         if you want to <span class="bold"><strong>find</strong></span> a sub-string within
49         the text that matches the expression then use regex_search instead.
50       </p>
51 <p>
52         <span class="bold"><strong>Q.</strong></span> Why does using parenthesis in a POSIX
53         regular expression change the result of a match?
54       </p>
55 <p>
56         <span class="bold"><strong>A.</strong></span> For POSIX (extended and basic) regular
57         expressions, but not for perl regexes, parentheses don't only mark; they
58         determine what the best match is as well. When the expression is compiled
59         as a POSIX basic or extended regex then Boost.Regex follows the POSIX standard
60         leftmost longest rule for determining what matched. So if there is more than
61         one possible match after considering the whole expression, it looks next
62         at the first sub-expression and then the second sub-expression and so on.
63         So...
64       </p>
65 <p>
66         "(0*)([0-9]*)" against "00123" would produce $1 = "00"
67         $2 = "123"
68       </p>
69 <p>
70         where as
71       </p>
72 <p>
73         "0*([0-9])*" against "00123" would produce $1 = "00123"
74       </p>
75 <p>
76         If you think about it, had $1 only matched the "123", this would
77         be "less good" than the match "00123" which is both further
78         to the left and longer. If you want $1 to match only the "123"
79         part, then you need to use something like:
80       </p>
81 <p>
82         "0*([1-9][0-9]*)"
83       </p>
84 <p>
85         as the expression.
86       </p>
87 <p>
88         <span class="bold"><strong>Q.</strong></span> Why don't character ranges work properly
89         (POSIX mode only)?
90       </p>
91 <p>
92         <span class="bold"><strong>A.</strong></span> The POSIX standard specifies that character
93         range expressions are locale sensitive - so for example the expression [A-Z]
94         will match any collating element that collates between 'A' and 'Z'. That
95         means that for most locales other than "C" or "POSIX",
96         [A-Z] would match the single character 't' for example, which is not what
97         most people expect - or at least not what most people have come to expect
98         from regular expression engines. For this reason, the default behaviour of
99         Boost.Regex (perl mode) is to turn locale sensitive collation off by not
100         setting the <code class="computeroutput"><span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">collate</span></code>
101         compile time flag. However if you set a non-default compile time flag - for
102         example <code class="computeroutput"><span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">extended</span></code> or <code class="computeroutput"><span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">basic</span></code>,
103         then locale dependent collation will be enabled, this also applies to the
104         POSIX API functions which use either <code class="computeroutput"><span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">extended</span></code>
105         or <code class="computeroutput"><span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">basic</span></code> internally. [Note - when <code class="computeroutput"><span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">nocollate</span></code> in effect, the library behaves
106         "as if" the LC_COLLATE locale category were always "C",
107         regardless of what its actually set to - end note].
108       </p>
109 <p>
110         <span class="bold"><strong>Q.</strong></span> Why are there no throw specifications
111         on any of the functions? What exceptions can the library throw?
112       </p>
113 <p>
114         <span class="bold"><strong>A.</strong></span> Not all compilers support (or honor)
115         throw specifications, others support them but with reduced efficiency. Throw
116         specifications may be added at a later date as compilers begin to handle
117         this better. The library should throw only three types of exception: [boost::regex_error]
118         can be thrown by <a class="link" href="../ref/basic_regex.html" title="basic_regex"><code class="computeroutput"><span class="identifier">basic_regex</span></code></a> when compiling a regular
119         expression, <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code> can be thrown when a call
120         to <code class="computeroutput"><span class="identifier">basic_regex</span><span class="special">::</span><span class="identifier">imbue</span></code> tries to open a message catalogue
121         that doesn't exist, or when a call to <a class="link" href="../ref/regex_search.html" title="regex_search"><code class="computeroutput"><span class="identifier">regex_search</span></code></a> or <a class="link" href="../ref/regex_match.html" title="regex_match"><code class="computeroutput"><span class="identifier">regex_match</span></code></a> results in an "everlasting"
122         search, or when a call to <code class="computeroutput"><span class="identifier">RegEx</span><span class="special">::</span><span class="identifier">GrepFiles</span></code>
123         or <code class="computeroutput"><span class="identifier">RegEx</span><span class="special">::</span><span class="identifier">FindFiles</span></code> tries to open a file that cannot
124         be opened, finally <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_alloc</span></code> can be thrown by just about any
125         of the functions in this library.
126       </p>
127 <p>
128         <span class="bold"><strong>Q.</strong></span> Why can't I use the "convenience"
129         versions of regex_match / regex_search / regex_grep / regex_format / regex_merge?
130       </p>
131 <p>
132         <span class="bold"><strong>A.</strong></span> These versions may or may not be available
133         depending upon the capabilities of your compiler, the rules determining the
134         format of these functions are quite complex - and only the versions visible
135         to a standard compliant compiler are given in the help. To find out what
136         your compiler supports, run &lt;boost/regex.hpp&gt; through your C++ pre-processor,
137         and search the output file for the function that you are interested in. Note
138         however, that very few current compilers still have problems with these overloaded
139         functions.
140       </p>
141 </div>
142 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
143 <td align="left"></td>
144 <td align="right"><div class="copyright-footer">Copyright &#169; 1998-2013 John Maddock<p>
145         Distributed under the Boost Software License, Version 1.0. (See accompanying
146         file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
147       </p>
148 </div></td>
149 </tr></table>
150 <hr>
151 <div class="spirit-nav">
152 <a accesskey="p" href="futher.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../background_information.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="performance.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
153 </div>
154 </body>
155 </html>