> Why do this regular expression not work:
> if (str.matches("^\\d*$") || str.matches("^\\d*" + dot + "$") ||
[quoted text clipped - 13 lines]
>
> Can somebody tell me, what's wrong and maybe shorten it?
It appears to work. It matches ",14" and "3," and "," in addition to
"314" and "3,14", though. You failed to give an example of a str that
you think should match and does not, or that you think should not
match and does.
"foo|bar|baz" matches "foo" or "bar" or "baz".
"foo,?bar" matches "foobar" or "foo,bar".
The anchors are redundant with .matches().