I
I
in8inity2016-01-11 14:13:40
Python
in8inity, 2016-01-11 14:13:40

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)

Tester result, 5 groups:
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`

The result of the program, 3 groups (not counting empty lines):
'1 and', '1', '/3 cups (225g) frozen* blueberries, not thawed'

Why is it so?
Advise, pliz, a correct tester, dividing into groups.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
in8inity, 2016-01-11
@in8inity

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

A
abs0lut, 2016-01-11
@abs0lut

regexr.com

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question