Answer the question
In order to leave comments, you need to log in
What are the online regular season testers who divide into groups?
The online tester (regex101) and the result of the program give different groups in the answer with the same regular expression.
The essence of the task: splitting the recipe line into an ingredient / quantity / measure / and a "tail"
sPattern = re.compile('''([a-z \-\,\']*) # для строк типа salt and pepper to taste
((?:\d+\ +)(?:and [0-9\/]+)?| # для записей c дробью (1 and 3/4 ...)
[\d\.\,\-]+)\s? # диапазон, допустимо с точкой (1,5-2...; 4-8...)
([\w\ \%\-\'\"]+) # мера, при наличии; ингредиент в простых продуктах
\(?([0-9\.\,\ ]+g?)?\)? # (эквивалент в граммах, при наличии, в скобках)
(.*) # ингредиент или пустая строка для простых продуктов
(?:( or .+)|\((.+)\)|\, (.+))? # довесок после запятой/скобок/или
''', re.IGNORECASE | re.VERBOSE)
1. [0-0] ``
2. [0-9] `1 and 1/3`
3. [10-15] `cups `
4. [16-20] `225g`
5. [21-53] `frozen* blueberries, not thawed`
'1 and', '1', '/3 cups (225g) frozen* blueberries, not thawed'
Answer the question
In order to leave comments, you need to log in
www.pcre.ru/eval and baco.su/articles/regularnye-vyrajeniya
Additionally, I had to replace spaces with the character class of spaces (\s), probably for my python it was important
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question