0

Hello I have a simple regex which should check if string ends with milliseconds (DOT, NUMBER, NUMBER, NUMBER, END OF STRING)

I set regex .\d{3}

and check it in several ways and this always returns false (even if there is pattern on the end):

enter image description here

Any idea whay this does not work? It works well on https://regex101.com/

J. Doe
  • 33
  • 3
  • 1
    Did you declare it as `"\\.\\d+$"`? Is the `$` expected to match end of string or line? Also, use `.find()`, not `matches()`. – Wiktor Stribiżew Aug 29 '16 at 09:35
  • As Wiktor said, double escape is the key. – revo Aug 29 '16 at 09:36
  • yes, you can see it on image at end of line 6 – J. Doe Aug 29 '16 at 09:38
  • private final static String REGEX_ENDS_WITH_MILLISECONDS = "\\.\\d{3}$"; – J. Doe Aug 29 '16 at 09:38
  • That means the only problem is that you use `matches()` instead of `find()`, so, the question is a dupe of http://stackoverflow.com/questions/30912978/java-regex-pattern-that-matches-in-any-online-tester-but-doesnt-in-eclipse. – Wiktor Stribiżew Aug 29 '16 at 09:39
  • if part is messed up a bit cause I try to find out why does not work :D it sensslessatm :) – J. Doe Aug 29 '16 at 09:39
  • And if you match question as EXACT DUPLICATE could you add link to other ticked instead to your name? – J. Doe Aug 29 '16 at 09:41
  • Revo you are wrong, Wiktor provided link to solution... matches check for whole string find it search if pattern is present in string... – J. Doe Aug 29 '16 at 09:49
  • Although you had one more misunderstanding to be solved, I wasn't wrong about what I have said. – revo Aug 29 '16 at 10:02

0 Answers0