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