[Solved] How to remove numbers from string which starts and ends with numbers?


simple using replaceAll() using ^\\d+|\\d+$ regex that looks for digits in the beginning and ending of the line.

System.out.println("1adfds23dfdsf121".replaceAll("^\\d+|\\d+$", "")); 

output:

adfds23dfdsf

EDIT

Regex explanation:

^     Start of line
 \d+   Any digit (one or more times)
|     OR
 \d+   Any digit (one or more times)
$     End of line

enter image description here

3

solved How to remove numbers from string which starts and ends with numbers?