Closed kzidane closed 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!
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
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."
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...".
Looks like you need a ! to disallow? Currently seems to require an exponent?
On Sunday, May 8, 2016, Kareem notifications@github.com wrote: