regex to parse out certain value that i want
<p>Using <a href="https://regex101.com/" rel="nofollow">https://regex101.com/</a></p>

<ul>
<li>MY current regex Expression: <code>^.*'(\d\s*.*)'*$</code></li>
</ul>

<p>which doesnt seem to be working. What is the right combination formula that i should use?</p>

<p>I want to able to parse out <strong>4</strong> variable namely
<strong>items, quantity, cost and Total</strong></p>

<p>MY CODE:</p>

<pre><code>import re

str = "xxxxxxxxxxxxxxxxxx" 
match = re.match(r"^.*'(\d\s*.*)'*$",str) 
print match.group(1)
</code></pre>

<p>The following regex matches each ingredient string and stores wanted informations into groups: <code>r'^(\d+)\s+([A-Za-z ]+)\s+(\d+(?:\.\d*))$'</code></p>

<p>It defines 3 groups each separated from other by spaces:</p>

<ul>
<li><code>^</code> marks the string start</li>
<li><code>(\d+)</code> is the first group and looks for at least one digit</li>
<li><code>\s+</code> is the first separation between groups and looks for at least one white character</li>
<li><code>([A-Za-z ]+)</code> is the second group and looks for a least one alphabetical character or space</li>
<li><code>\s+</code> is the second separation beween groups and looks for at least one white character</li>
<li><code>(\d+(?:\.\d*)</code> is the third group and looks for at least one digit with eventually a decimal point and some other digits</li>
<li><code>$</code> marks the string end</li>
</ul>

<p>A regex to obtain the total does not need to be explained I think.</p>

<p>Here is a test code using your test data. Is should be a good starting point:</p>

<pre><code>import re

TEST_DATA = ['Table: Waiter: kenny',
             '======================================',
             '1 SAUSAGE WRAPPED WITH B 10.00',
             '1 ESCARGOT WITH GARLIC H 12.00',
             '1 PAN SEARED FOIE GRAS 15.00',
             '1 SAUTE FIELD MUSHROOM W 9.00',
             '1 CRISPY CHICKEN WINGS 7.00',
             '1 ONION RINGS 6.00',
             '----------------------------------',
             'TOTAL 59.00',
             'CASH 59.00',
             'CHANGE 0.00',
             'Signature:__________________________',
             'Thank you &amp; see you again soon!']

INGREDIENT_RE = re.compile(r'^(\d+)\s+([A-Za-z ]+)\s+(\d+(?:\.\d*))$')
TOTAL_RE = re.compile(r'^TOTAL (.+)$')

ingredients = []
total = None
for string in TEST_DATA:
    match = INGREDIENT_RE.match(string)
    if match:
        ingredients.append(match.groups())
        continue
    match = TOTAL_RE.match(string)
    if match:
        total = match.groups()[0]
        break

print(ingredients)
print(total)
</code></pre>

<p>this prints:</p>

<pre><code>[('1', 'SAUSAGE WRAPPED WITH B', '10.00'), ('1', 'ESCARGOT WITH GARLIC H', '12.00'), ('1', 'PAN SEARED FOIE GRAS', '15.00'), ('1', 'SAUTE FIELD MUSHROOM W', '9.00'), ('1', 'CRISPY CHICKEN WINGS', '7.00'), ('1', 'ONION RINGS', '6.00')]
59.00
</code></pre>

<hr>

<p>Edit on Python raw strings:</p>

<p>The <code>r</code> character before a Python string indicates that it is a raw string, which means that spÃ©cial characters (like <code>\t</code>, <code>\n</code>, etc...) are not interpreted.</p>

<p>To be clear, and for example, in a standard string <code>\t</code> is one tabulation character. It a raw string it is two characters: <code>\</code> and <code>t</code>.</p>

<p><code>r'\t'</code> is equivalent to <code>'\\t'</code>.</p>

<p><a href="https://docs.python.org/2/reference/lexical_analysis.html#string-literals" rel="nofollow">more details in the doc</a></p>

python regex