用户输入 2"3' 或者 2 feet 3 inches
需要把2 ,3 提取出来
下面是我写的,发现无法匹配string JoinedFootUnits = "foots|foot|feets|feet|ft|f|\"";
string JoinedInchUnits = "inches|inchs|inch|in|i|\'"; string pattern = @" \b
(?<footHeight>(\d+))
(\s*)
(?<footUnit>[" + JoinedFootUnits + @"]{1})
(\s*)
(?<inchHeight>\d+)*
(\s*)
(?<inchUnit>[" + JoinedInchUnits + @"])*
\b
";
Regex regex = new Regex(pattern, RegexOptions.IgnorePatternWhitespace); Match match = regex.Match(height);
(?<footHeight>\d+)\s*(?<footUnit>"|feet)\s*(?<inchesHeight>\d+)\s*(?<inchesUnit>"|inches)
re.Replace(string,"");
不行,仅仅能提取 foot 不能提起 inches.