Home > Blockchain >  Jquery or javascript regex to extract decimals
Jquery or javascript regex to extract decimals

Time:06-30

I need to write a regex in javascript or jquery to extract all decimals with this format "XXXXXX,XX".

My string to analyse is :

aaawhatyouwant"4666","bla bla","5,00","27/06/2022","09:00","14:00","","0x7fffffffffffffff","4670","0,50","28/06/2022","07:00","07:30","4669","08:00","08:30"whatyouwantbbb

And my regex is:

/aaa.*(?:(?:"(\d ,\d\d)"). )bbb/g

So expected results would be:

5,00 is missing!
0,50 ok

Any help would be appreciated!:)

Regards François

CodePudding user response:

If you want to match only comma separated decimal numbers try this:

/(\d ,\d )/g

You can test it here: https://regexr.com/6oop4

To match comma and period separated numbers try this:

(\d (,|\.)\d )

CodePudding user response:

Ok, correct regex expression is:

/(?:(?:"(\d ,\d\d)"))/g

I get my 2 results 5,00 and 0,50 now !

Thanks!

  • Related