Match
std::regex_match
determines if text matches a text pattern. You can further analyse the search result of type std::match_results
.
The code snippet below shows three simple applications of std::regex_match
: a C string, a C++ string and a range returning only a boolean. The three variants are available for std::match_results
objects respectively.
std::match
// match.cpp
...
#include
<regex>
...
std
::
string
numberRegEx
(
R
"
(
[-+]?([0-9]*\.[0-9]+|[0-9]+)
)
"
);
std
::
regex
rgx
(
numberRegEx
);
const
char
*
numChar
{
"2011"
};
if
(
std
::
regex_match
(
numChar
,
rgx
)){
std
::
cout
<<
numChar
<<
" is a number."
<<
std
::
endl
;
}
// 2011 is a number.
const
std
::
string
numStr
{
"3.14159265359"
};
if
(
std
::
regex_match
(
numStr
,
rgx
)){
std
::
cout
<<
numStr
<<
" is a number."
<<
std
::
endl
;
}
// 3.14159265359 is a number.
const
...