Sublime Forum

How do I use a part of the matched text in regex for Sublime Text, in the replacement?

#1

If I have

width: 12px 0;
width: 24px 0;

how can I use regex to replace it with

width: 12px 0px;
width: 24px 0px;

While keeping the first number intact?

I am using Sublime Text. I tried searching Google and Bing and I couldn’t find anything helpful. Using :[0-9]*px 0; and :${m}px 0px; doesn’t work.

0 Likes

#2

Hi,

As far as I know, the captured match (stuff in parenthesis) can be retrieved in REPLACE as $1, $2, and so on. The entire match is in $0. Can you try the following in the FIND field:

(width: [0-9]+px 0)(;)

And in the REPLACE field:

$1px$2

I hope this helps. Best

0 Likes

#3

Depending on your needs you can also just select the “px 0;”, press alt+f3 to select all occurrences and then right-arrow, left-arrow and type px.

1 Like

#4

That answer doesn’t work but I got a working answer on Stack Overflow.

0 Likes