Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to replace decimal and integer strings with numbers

In sublime text I have some data that contains numeric strings. Some are decimals and others are integers. I would like to remove the quotes to have them just as numbers. Is there a regular expression I can use to achieve this. I would also need a replace expression to go with it.

E.g.

'0'    => 0
'1'    => 1
'1234' => 1234
'1.23' => 1.23

I've extensively searched for a solution with no luck.

like image 610
harryg Avatar asked Jun 25 '14 11:06

harryg


1 Answers

Something like this should work: '(\d+(\.\d+)?)'. This will capture the number and place it in a group. You can then replace that with either $1 or \1. This should backreference the matched group, which is the number itself.

Regex explanation available here.

like image 92
npinti Avatar answered Sep 30 '22 16:09

npinti