A = "\\d{8}-?\\d{1}"; str = "123456-123456" regex_search(A, str, match_result); will return true and regex_match(A, match_result) return false