The match_results::length() is a inbuilt function in C++ which is used to return the length of a particular match in the match_results object.
smatch_name.length(n) Note: smatch_name is an object of match_results class.
Parameters: It accepts a single parameter n which specifies the Match number. It is lower than match_results::size. The match number 0 represents the entire matched expression. Subsequent match numbers identify the sub-expressions if any. The passed integral is an unsigned integral type.
Return Value:It returns the length of the n-th match in the match_results object.
Note: First element always contains the whole regex match while the others conatain the particular Capturing Group.
Below programs illustrate the above function.
match 0 has a length of 13 match 1 has a length of 5 match 2 has a length of 8
max-length sub match is forgeeks with a length of 8
- Variable Length Arrays in C and C++
- 5 Different methods to find length of a string in C++
- Counts of distinct consecutive sub-string of length two using C++ STL
- Find words which are greater than given length k using stringstream
- Different ways to use Const with Reference to a Pointer in C++
- std::to_address in C++ with Examples
- Program to create Custom Vector Class in C++
- std::is_trivially_copy_constructible in C/C++
- Difference between Python and C++
- tgamma() method in C/C++ with Examples
- boost::type_traits::is_array Template in C++
- boost is_pointer template in C++
- Remove duplicate words from Sentence using Regular Expression
- Stack of Pair in C++ STL with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.