Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect regex for floating point numbers #2735

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Mayuresh-22
Copy link

Fixed Issue #2711

Above issue talks about replacing the DNUM regex:

DNUM ([0-9]*(_[0-9]+)*[\.]{LNUM}) | ({LNUM}[\.][0-9]*(_[0-9]+)*)

with:

DNUM (([0-9]+(_[0-9]+)*)?\.{LNUM}) | ({LNUM}\.([0-9]+(_[0-9]+)*)?)

In this PR required changes are done.

@@ -29,7 +29,7 @@ $d = 1_234.567; // as of PHP 7.4.0
<programlisting>
<![CDATA[
LNUM [0-9]+(_[0-9]+)*
DNUM ([0-9]*(_[0-9]+)*[\.]{LNUM}) | ({LNUM}[\.][0-9]*(_[0-9]+)*)
DNUM (([0-9]+(_[0-9]+)*)?\.{LNUM}) | ({LNUM}\.([0-9]+(_[0-9]+)*)?)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the ? needed? Shouldn't they be covered with the * quantifier?

Copy link
Contributor

@diesirae68 diesirae68 Sep 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ? allows numbers of the form: .123 or 123.

([0-9]+(_[0-9]+)*)? prohibits the use of the separator _ at the beginning and at the end of the number.

_123 or 123_ are incorrect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[0-9]*(_[0-9]+)* allows the separator _ at the beginning (this is a mistake).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't it be written as {LNUM}?\.{LNUM} | {LNUM}\.{LNUM}? then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sure

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This form of regex is more compact and looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants