cs50 / libcs50-java

CS50 Library for Java
GNU General Public License v3.0
19 stars 11 forks source link

disallows exponents #3

Closed kzidane closed 8 years ago

dmalan commented 8 years ago

Looks like you need a ! to disallow? Currently seems to require an exponent?

On Sunday, May 8, 2016, Kareem notifications@github.com wrote:


You can view, comment on, or merge this pull request online at:

https://github.com/cs50/java/pull/3 Commit Summary

  • disallows exponents

File Changes

Patch Links:

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/cs50/java/pull/3

kzidane commented 8 years ago

@dmalan the ^ is for matching anything but the provided chars. see https://docs.oracle.com/javase/tutorial/essential/regex/char_classes.html!

dmalan commented 8 years ago

Did you test? The current expression just means "if the string has at least one char that isn't E or e", which isn't what you want!

On Sunday, May 8, 2016, Kareem notifications@github.com wrote:

@dmalan https://github.com/dmalan the ^ is for matching anything but the provided chars. see https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html!

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/cs50/java/pull/3#issuecomment-217745793

kzidane commented 8 years ago

yes, I did, and indeed it disallows strings with at least one char that is an 'E' or an 'e' while still allowing regular floating-points and disallowing unparsable strings.

current expression means "return true if string has only chars that are not 'E's or 'e's. at least one of them."

dmalan commented 8 years ago

Ah, my apologies, I had no idea String.matches matches full strings (with an implied ^ and $). Doesn't even seem to be documented! Cf. http://stackoverflow.com/a/18525028/5156190.

Just committed https://github.com/cs50/java/commit/9cb916fd15f571c58d25103f9b38b8ddce708c55. How's that look? I took the more verbose approach so that the semantics are "if s doesn't match a string containing these chars...".