jmann jmann - 1 year ago 72
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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download