2

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.

2
  • 1
    Try \d+(?:[.,]\d+)*(?=\s*BDT)|(?<=TK\s)\d+(?:[.,]\d+)* if you are using the pattern in an environment that fetches the first match. See this regex demo. Commented Sep 5, 2021 at 19:47
  • 1
    Yeah, I am just matching the first case and it works. Thanks :) Commented Sep 5, 2021 at 19:56

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.