user2716736
user2716736

Reputation: 65

Sublime regex comma replace character

I have a approx 22000 data items in the file which has data given as below

a0001, = , [,23.3,88.9,]
b0001, = , [, 21.3,98.2,]
b2312, = , [, 11.3,55.1,]

I am using Sublime and trying to remove / clean data so that it can be used in a ruby application I am trying to remove few commas using sublime find / replace option Even after trying various regex option couldn't get anything to give me data in the following form

a0001 =  [23.3,88.9]
b0001 =  [21.3,98.2]
b2312 =  [11.3,55.1]

in the form of arrays

Help needed please...

Upvotes: 0

Views: 834

Answers (2)

Haji Rahmatullah
Haji Rahmatullah

Reputation: 430

You can also try below regex

Find what: [,]|(\d,\d+)
Replace with: $1

Upvotes: 0

tadman
tadman

Reputation: 211580

Pure regular expression version:

^(\w+),\s*=\s*,\s*\[,\s*(\d+\.\d+),\s*(\d+\.\d+),\]

Replace with:

$1 = [ $2, $3 ]

The goal here is to capture the data using (...) and then later position and format it as precisely as you want. Using \s* makes your expression a lot more lenient regarding space that may or may not be there.

Upvotes: 1

Related Questions