Jin
Jin

Reputation: 932

Regular expression to replace txt in Sublime text editor

I have thousands of rows to edit so need to use regex.

One row is something like this.

T1,1,Example Text1 Text
T2,2,Example Text 2 Text
T3,3,Example Text 3 Text3

I want to convert this data to like this.

{pid:T1,sid:1,name:"Example Text1 Text"},
{pid:T2,sid:2,name:"Test Text1 Text"},
{pid:T3,sid:3,name:"Content Text1 Text"},

How can I do this?

I've tried to replace first and last characters using ^ & $. but I want to convert ",1," to ",sid:1," and "Example Test" to "name:'Example Text'".

Anyhelp would be appreciate.

Upvotes: 0

Views: 711

Answers (1)

Kaspar Lee
Kaspar Lee

Reputation: 5596

Find ^(T\d+,)(\d+,)(.*)$ and replace with {pid:\1sid:\2name:"\3"},

Make sure that the search is set to use Regex.

Matching Regex Breakdown:

^    # Start of Line
(    # Capture Group #1 (for Tx)
  T    # "T"
  \d+  # 1 or more digits (T1, T2, T27, etc.)
  ,    # ","
)
(    # Capture Group #2 (for the `sid`)
  \d+  # 1 or more digits (for the `sid`)
  ,    # ","
)
(    # Capture Group #3 (for the string)
  .*   # String (name)
)
$    # End of Line

Upvotes: 3

Related Questions