在 Sublime 文本编辑器中替换 txt 的正则表达式
Regular expression to replace txt in Sublime text editor
我有数千行要编辑,因此需要使用正则表达式。
一行是这样的。
T1,1,Example Text1 Text
T2,2,Example Text 2 Text
T3,3,Example Text 3 Text3
我想把这个数据转换成这样。
{pid:T1,sid:1,name:"Example Text1 Text"},
{pid:T2,sid:2,name:"Test Text1 Text"},
{pid:T3,sid:3,name:"Content Text1 Text"},
我该怎么做?
我尝试使用 ^ 和 $ 替换第一个和最后一个字符。
但我想将“,1,”转换为“,sid:1”,并将 "Example Test" 转换为 "name:'Example Text'"。
任何帮助将不胜感激。
找到^(T\d+,)(\d+,)(.*)$
并替换为{pid:sid:name:""},
确保搜索设置为使用正则表达式。
匹配正则表达式分解:
^ # 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
我有数千行要编辑,因此需要使用正则表达式。
一行是这样的。
T1,1,Example Text1 Text
T2,2,Example Text 2 Text
T3,3,Example Text 3 Text3
我想把这个数据转换成这样。
{pid:T1,sid:1,name:"Example Text1 Text"},
{pid:T2,sid:2,name:"Test Text1 Text"},
{pid:T3,sid:3,name:"Content Text1 Text"},
我该怎么做?
我尝试使用 ^ 和 $ 替换第一个和最后一个字符。 但我想将“,1,”转换为“,sid:1”,并将 "Example Test" 转换为 "name:'Example Text'"。
任何帮助将不胜感激。
找到^(T\d+,)(\d+,)(.*)$
并替换为{pid:sid:name:""},
确保搜索设置为使用正则表达式。
匹配正则表达式分解:
^ # 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