0
我想在输入无效时向用户显示一些消息。如何使用正则表达式提取字符串的不匹配部分
我写此正则表达式,以validade这种模式:(10个字符名称)(0-9之间号)
例如布鲁诺3
^([\w]{1,10})(\s[\d]{1})$
当用户输入任何无效的字符串,是否有可能知道什么组是无效的,并打印消息? 类似的东西:
if (regex_match(user_input, e))
{
cout << "input ok" << endl;
}
else
{
if (group1 is invalid)
{
cout << "The name must have length less than 10 characters" << endl;
}
if (group2 is invalid)
{
cout << "The command must be between 0 - 9" << endl;
}
}
'[\ d] {1}'可以是'\ d' – 4castle
您提出了哪些代码?它有什么问题? –
@WiktorStribiżew我编辑了问题 – Bruno