c++ - C++11 regex matching a full word that does not end with a period? -
i trying match full word not end period. have following regex negative lookahead, std::regex rex("\\w+(?!\\.)");
however still producing match on words "joe." missing?
you need make sure word followed word boundary:
std::regex rex(r"(\w+\b(?!\.))"); see regex demo
otherwise, backtracking occurs , find jo in joe. your pattern.
i advise use raw string literals when defining regex, rid of excessive backslashes way.
Comments
Post a Comment