Regex extract number from string

Viewed 61

I need to extract the highlighted number from these two strings.

  1. Dear IBBL CH Purchased 10.00 BDT at grameenphone.com, BD on 05.09.21 20:06 Card ***9793 Avl Bal: 930.53 BDT Help:16259 Get 10%discount from DARAZ *T&C

  2. TK 20,312.84 has been refunded into your A/C **04994509 at 10/01/21 03:27 PM for NPSB Transfer: 71210110003106, Balance:21,019.50. Help:16259,8331090 - IBBL iBanking

I have tried (?<=tk )(.+\d) for the first one and \d.+ (?=bdt) for the second one, but doesn't work.

1 Answers

You can use

\d+(?:[.,]\d+)*(?=\s*BDT)|(?<=TK\s)\d+(?:[.,]\d+)*

See the regex demo. Details:

  • \d+ - one or more digits
  • (?:[.,]\d+)* - zero or more occurrences of a dot or comma and then one or more digits
  • (?=\s*BDT) - a location immediately followed with zero or more whitespaces and then BDT
  • | - or
  • (?<=TK\s) - a location immediately preceded with TK and a whitespace
  • \d+(?:[.,]\d+)* - one or more digits and then zero or more occurrences of a dot or comma and then one or more digits
Related