1

Please help,

I need to extract a text from a long sentence

The text is as follows :

Current Balance: INR2,137,381.99 8/9/2020 Impaired normal

I would like to extract the amount from the above text and I used the regex

(?<=Current Balance:).+(?=/s)

And nothing getting..and I tried

(?<=Current Balance:).+(?=Impaired) and showing result : AED2,137,381.99 8/9/2020

So simply I want to note the text ending with space (the date is not static) , can anyone help on this?

ggorlen
  • 44,755
  • 7
  • 76
  • 106
sreenath s
  • 13
  • 2

1 Answers1

0

Use

/(?<=Current Balance:\s*)\S+/

See proof. It matches one or more non-whitespace characters after Current Balance phrase, possibly followed with any amount of whitespace.

const string = "Current Balance: INR2,137,381.99 8/9/2020 Impaired normal";
const regex = /(?<=Current Balance:\s*)\S+/;
console.log(string.match(regex)[0])

Or, use capturing mechanism:

/Current Balance:\s*(\S+)/

JavaScript:

const string = "Current Balance: INR2,137,381.99 8/9/2020 Impaired normal";
const regex = /Current Balance:\s*(\S+)/;
console.log(string.match(regex)[1])
Ryszard Czech
  • 18,032
  • 4
  • 24
  • 37
  • http://regexstorm.net/tester it is not working in this tool – sreenath s Aug 01 '20 at 19:33
  • @sreenaths Regexstorm is for .NET regex, are you using JavaScript or .NET? By the way, it seems working, see [demo](http://regexstorm.net/tester?p=%28%3f%3c%3dCurrent+Balance%3a%5cs*%29%5cS%2b&i=Current+Balance%3a+INR2%2c137%2c381.99+8%2f9%2f2020+Impaired+normal). – Ryszard Czech Aug 01 '20 at 19:42