在Sublime文本中查找和替换RegEx

时间:2014-08-03 21:54:00

标签: regex replace sass sublimetext

我使用sass mixin,我希望使用正则表达式更改旧代码 例如,我有下一个scss代码

margin-left:30px;
margin-right:3em;
padding-right:1rem;

@include margin-start(30px);
@include margin-end(3em);
@include padding-end(1rem);

2 个答案:

答案 0 :(得分:1)

最后我找到了解决方案:

Find: (margin-right:)\s(\-|((.*){1,3}))(\;$)
Replace: @include margin-end(\3)

Find: (margin-left:)\s(\-|((.*){1,3}))(\;$)
Replace: @include margin-start(\3)

Find: (padding-right:)\s(\-|((.*){1,3}))(\;$)
Replace: @include padding-end(\3)

答案 1 :(得分:1)

您可以使用以下正则表达式:

(\w+\-\w+:\w+;)

<强> Working demo

匹配信息

MATCH 1
1.  [0-17]  `margin-left:30px;`
MATCH 2
1.  [18-35] `margin-right:3em;`
MATCH 3
1.  [36-55] `padding-right:1rem;`

<强>代换

@include margin-left:30px;
@include margin-right:3em;
@include padding-right:1rem;