Regexp,用于带有数字的特定单词

Regexp for a particular word with a digit

本文关键字:单词 数字 用于 Regexp      更新时间:2023-10-16

我似乎无法为以下内容找到正则表达式。。

Earth+任何数字。

例如

Earth1
Earth2
Earth3
Earth10
Earth20
...

我以为这应该行得通,但不行。。

std::regex("Earthd$")

首先,您必须添加一个斜线来转义当前斜线。第二-添加重复(+),因为d表示数字(而不是数字):

std::regex("Earth\d+$")