Difference between regex_match and regex_search?

前端 未结 4 1963
渐次进展
渐次进展 2020-12-06 09:02

I was experimenting with regular expression in trying to make an answer to this question, and found that while regex_match finds a match, regex_search

4条回答
  •  旧巷少年郎
    2020-12-06 09:51

    Assuming that C++ and Boost Regex have a similar structure and functionality, the difference between regex_match and regex_search is explained here:

    The regex_match() algorithm will only report success if the regex matches the whole input, from beginning to end. If the regex matches only a part of the input, regex_match() will return false. If you want to search through the string looking for sub-strings that the regex matches, use the regex_search() algorithm.

提交回复
热议问题