Skip to content

Updated integer regexp to allow for negatives#40

Open
arecker wants to merge 1 commit into
tdryer:masterfrom
arecker:todos
Open

Updated integer regexp to allow for negatives#40
arecker wants to merge 1 commit into
tdryer:masterfrom
arecker:todos

Conversation

@arecker
Copy link
Copy Markdown

@arecker arecker commented Nov 27, 2014

Found this while looking for TODOs

Implemented this pattern instead. Added a unit test and it seems to be working.

Comment thread hangups/javascript.py
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can you explain what the regular expression is doing? Why not just [-+]?\d+?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No, I can't explain it : ) I'm not the best with these. I was going off of the SO link I found + the unit test. I linked it in the PR. There is an explation there.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[+-]?

one of +, -, or nothing

(?<!\.)

Negative lookbehind, makes sure that a literal dot will not be matched at this position

\b

“the boundary between a word char (\w) and something that is not a word char”

[0-9]+

One or more digit

\b

-''-

(?!\.[0-9])

Negative lookahead, will make sure a literal dot followed by a digit is not matched


All in all, it means that it will match things like 42, +42, and -42, but not floats like 42.6 or .42

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