jmann jmann - 7 months ago 34
Java Question

regex for '(number)'

I need to replace all the

s around numbers, to nothing.. for example:

'1' to 1

'100' to 100

which is the optimal way to do this? is there a regex to do this so I can use it in the
function of the


You can use replaceAll method with regex support:

str = str.replaceAll("'(\\d+)'", "$1");

(\\d+) will match and group digits surrounded by single quotes on either side and then we use $1 in replacement which is the back-reference to captured value in regex.