简体   繁体   中英

Jquery or javascript regex to extract decimals

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

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+)

Ok, with this regex expression :

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

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

But when I add fixed start and end, I get only one result...

/aaawhatyouwant.*(?:(?:"(\d+,\d\d)").*)+.*whatyouwantbbb/g

Any suggestion ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM