<p>以下代码适用于示例SMS:</p>
<pre><code>import re
def split_str(s):
print('Spent/Added:',re.sub('.*(Spent|Added).*', '\\1', s))
print('Amount Type:', re.sub('.*?\s+?([a-zA-Z\W]+)\s+?[0-9]+.*', '\\1', s))
print('Amount:',re.sub('.*?[A-Za-z\W]+(.*?)\sat.*', '\\1', s))
print('Location where used:',re.sub('.*?at\s+(.*?)\s+from.*', '\\1', s))
print('Card Number:',re.sub('.*?((X{4})([0-9]{4})).*?', '\\1', s))
print('Full Card Number:',re.sub('.*?(([0-9]{4})\s+([0-9]{4})\s+([0-9]{4})\s+([0-9]{4})).*?', '\\1', s))
</code></pre>
<p><strong>示例1:</strong></p>
<pre><code>s = 'Spent Rs 300.00 at Shop Name from card number XXXX2123'
split_str(s)
</code></pre>
<p>结果:</p>
<pre><code>Spent/Added: Spent
Amount Type: Rs
Amount: 300.00
Location where used: Shop Name
Card Number: XXXX2123
Full Card Number: Spent Rs 300.00 at Shop Name from card number XXXX2123
</code></pre>
<p><strong>示例2:</strong></p>
<pre><code>s = 'Spent $ 3 000 000 000.78 at Bgees & Inc. from card number 1111 2222 3333 4444'
split_str(s)
</code></pre>
<p>结果:</p>
<pre><code>Spent/Added: Spent
Amount Type: $
Amount: 3 000 000 000.78
Location where used: Bgees & Inc.
Card Number: Spent $ 3 000 000 000.78 at Bgees & Inc. from card number 1111 2222 3333 4444
Full Card Number: 1111 2222 3333 4444
</code></pre>