我是正则表达式领域的新手。
我在这里要做的是验证用户在文本框中输入的数据。
我想要允许的内容:
正int值后跟mm/cm/km/in/ft
e.g. 1km, 12mm, 123in
是允许的。
我在这里使用std::regex
。
但是我在验证最后一个标签时遇到了困难,该标签可以是mm,cm,km,in,ft.
我写过这样的话:
std::regex_match( str, std::regex("[0-9]*[^a-zA-Z]*in$") );
// But this will suffice only for the int values followd by inches,
我想知道如何写一个正则表达式,如果我们在值的末尾有mm,cm,km,in,ft
之外的任何内容,它们将返回true。
答案 0 :(得分:3)
std::regex_match( str, std::regex("[0-9]\*[^a-zA-Z]\*(mm|cm|km|in|ft)$") );
答案 1 :(得分:3)