Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex issue - asterisk after \d

Tags:

regex

I'm using http://gskinner.com/RegExr/ to test my regex: [+-]?\d+\.?\d*(e[+-]?\d+)?. It's supposed to match floating point numbers. Currently it doesn't match .x, but I want to make it do that.

I tried changing it to [+-]?\d*\.?\d*(e[+-]?\d+)? (changed + to *) but that's an error. What's going wrong here?

Update: is it because everything is optional?

like image 730
Frank Epps Avatar asked Feb 16 '26 21:02

Frank Epps


1 Answers

Change the \.? to \. and it will work:

[+-]?\d*\.\d*(e[+-]?\d+)?

I suppose that the point is not optional.

But if you want to make it so, then describe it better with [.]+.

As @h2ooooooo mentioned it seems to be a bug in the as3 implementation of regex.

\d+\.?\d+ // works
\d*\.?\d+ // works
\d*\.?\d* // does not work
\d?\.?\d? // does not work
like image 124
Besnik Avatar answered Feb 20 '26 11:02

Besnik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!