复杂PHP正则表达式~([0-9 /]+)(cup|tablespoon)s的含义?([z] +) ~我


meaning of complex php regular expression ~([0-9 /]+) (cup|tablespoon)s? ([-A-Z ]+)~i

谁能给我解释一下?它会变成一个preg_match_all()函数

~([0-9 /]+) (cup|tablespoon)s? ([-A-Z ]+)~i

很可能来自菜谱。当输入:

时,正则表达式将匹配
  • 以任意数字、空格或斜杠开头,任意次数
  • 后面跟着"cup"、"cups"、"tablespoon"或" tables汤匙"
  • 后面跟着任何大写字母、破折号或空格
  • 不分大小写

处理:

3 cups water
1 tablespoon TOOTHPASTE
1/3 cups Apple Juice
1/3/5 6 cups ASDF-TEST TEST

边注:你下次应该谷歌一下。