java - Regex to test if a string ends with a number -
i'd test if string ends a digit. expect following java line print true. why print false?
system.out.println("i end number 4".matches("\\d$"));
your regex not match entire string last part. try below code , should work fine matches entire string.
system.out.println("i end number 4".matches("^.+?\\d$"));
you can test quick check on online regex testers one: http://www.regexplanet.com/simple/index.html. gives should use in java code in results appropriate escapes.
the .+ ensure there atleast 1 character before digit. ? ensure lazy match instead of greedy match.
Comments
Post a Comment