]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/regex/example/snippets/partial_regex_match.cpp
3 * Copyright (c) 1998-2002
6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE partial_regex_match.cpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: regex_match example using partial matches.
19 #include <boost/regex.hpp>
23 boost::regex
e("(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})");
25 bool is_possible_card_number(const std::string
& input
)
28 // return false for partial match, true for full match, or throw for
29 // impossible match based on what we have so far...
30 boost::match_results
<std::string::const_iterator
> what
;
31 if(0 == boost::regex_match(input
, what
, e
, boost::match_default
| boost::match_partial
))
33 // the input so far could not possibly be valid so reject it:
34 throw std::runtime_error("Invalid data entered - this could not possibly be a valid card number");
36 // OK so far so good, but have we finished?
39 // excellent, we have a result:
42 // what we have so far is only a partial match...
46 int main(int argc
, char* argv
[])
54 if(is_possible_card_number(input
))
56 std::cout
<< "Matched OK..." << std::endl
;
59 std::cout
<< "Got a partial match..." << std::endl
;
61 catch(const std::exception
& e
)
63 std::cout
<< e
.what() << std::endl
;