Skip to content
Advertisement

regex lookahead AND look behind

I have the following 2 variations of scraped data:

JavaScript

and

JavaScript

I’d like to make one regular expression that gets the percentage as a float, so in the first instance 3.0 and in the second 3.57

I’ve tried this so far:

JavaScript

Which works for the variation 2 but not variaton 1.

Advertisement

Answer

You may try this code to grab your percent values and convert them into float:

JavaScript

RegEx Demo

Online Code Demo

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement