Java - Check if last characters in a string are numeric
java
Solution
You could simply use `id.matches(".\\d+")`. To check if `id` starts with `E`, `S` or `X` followed by a string of digits, however, you could use
id.matches("[ESX]\\d+")
Relevant Documentation
- `matches`
Problem
I'd like to know what I can use to check if the last characters in a string are numeric. For example for the ID: "S000123" . I used the following to check if it starts with E, S or X. ``` if(! id.startsWith("E") || ! id.startsWith("S") || ! id.startsWith("X")) { alertinputError("Incorrect format in the ID field", lineNum); return; } ``` Thanks.