Match fractional number javascript

Asked

Viewed 183 times

1

I have a script and in one of the lines:

return $flag.text().match(/[0-9 ]+(?=\%)/i);

reads the numbers of a tag p.

Ex:

<p>Desconto 15%</p> 

In case he will read the number 15.

As far as I know this line does not read the number with semicolon ex: 9.09 or 9.09 <br/>.

In this example it reads only to the comma, as I would for this script to read the numbers after the comma ?

  • I just tested and unfortunately not :/

  • Thiago, the answer below solved the problem? here has a variant expression of that posted in the reply.

1 answer

2

You just need to add one . and , in the expression leaving so /[0-9,\.]+(?=\%)/. The modifier i is not necessary in that situation.

Fiddle

  • Guy unfortunately in a funnel :(

  • It will not work if you have "space" example 15 %

Browser other questions tagged

You are not signed in. Login or sign up in order to post.