Adel
Adel

Reputation: 6288

Find and Replace with RegEx in Sublime Text

I use sass mixin and i want change my old code using regex
for example i have the next scss code

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

to

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

Upvotes: 1

Views: 410

Answers (2)

Adel
Adel

Reputation: 6288

Finally i find solution :

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)

Upvotes: 1

Federico Piazza
Federico Piazza

Reputation: 31035

You can use the following regex:

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

Working demo

Match information

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

SUBSTITUTION

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

Upvotes: 1

Related Questions