c++ - Regular expression to match one or more characters every type? -
there 3 types of characters: a-z
, a-z
, 0-9
.
how write regular expression match words have 1 or more characters in 3 types?
for example:
match: abacc88, ua8za8, 88aa
no match: abc, 118, aa7, xxzz, xyz111
this boost::regex re("^[a-za-z0-9]+$");
doesn't work.
thanks
assuming you're testing each word separately:
boost::regex re("(?=.*[a-z])(?=.*[a-z])(?=.*[0-9])");
no need anchors.
actually, in case boost doesn't support lookarounds:
boost::regex re(".*[a-z].*([a-z].*[0-9]|[0-9].*[a-z])|.*[a-z].*([a-z].*[0-9]|[0-9].*[a-z])|.*[0-9].*([a-z].*[a-z]|[a-z].*[a-z])");
this every combination, @bill has pointed out.
Comments
Post a Comment