Regular expression is a sequence of characters that define a search pattern, mainly for use in pattern matching with strings, or string matching, ie “find and replace” -like operations.
Check regular expressions: regex101.com
SMS message: “01.01.2016 12:12 Card 4444, balance 12345.67 USD. Bonus 0 USD”
Simple template for balance:
Search the balance only for 4444 card:
The template will be “4444.*balance (.*?) USD“, where “.*” – Any character 0 or more times. This pattern will look for a value only in SMS with text: “4444[any text]balance [value] USD”.
Search the balance for not 4444 card:
The template will be “^(?!.*4444). *balance (.*?) USD“, where “^(?!.*4444)” – check the text “4444”. The template will look for value only if there is no 4444 in sms text.
Special characters:
Use special characters, for search time:
To find the time in the SMS, using first example, template will be “01.01.2016 (.*?) Card“. But this is the wrong template, because the date can be any, not only 01.01.16. So use special characters: