![]() |
VOOZH | about |
smatch is an instantiation of the match_results class template for matches on string objects. Functions that can be called using smatch: str(), position(), and length() member functions of the match_results object can be called to get the text that was matched, or the starting position and its length of the match relative to the subject string.
What is capturing group ? Examples:
Example-1:
Suppose you create a regex object like : regex re("(geeks)(.*)")
Here no of capturing group is = 2
[ one is "geeks" and second is any character after "geeks" ].
Example-2:
regex re("a(b)c")
Here no of capturing group is = 1[ 'b' is the capturing group].
whatever within '(' and ')' braces is treated as capturing group.
Below is the program to show the working of smatch:
Match size = 3 Whole match : geeksforgeeks First capturing group is 'geeks' which is captured at index 0 Second capturing group is 'forgeeks' which is captured at index 5
Time Complexity: O(n)
Auxiliary Space: O(1)