In the Sublime Text editor window there are two lines:

011 011 

I need to turn this into:

 0;1;1 0;1;1 

Those. put a semicolon after each digit. If the number is at the end of the line, then after it ; not put .

Now I do it in two bars:

1) find: (\d) replace: $1; I get:

 0;1;1; 0;1;1; 

2) Delete ; , those at the end - find ;$ replace:

and get what I wanted:

 0;1;1 0;1;1 

How do I do the same thing, but with one regular expression?

1 answer 1

Such problems can be effectively solved using the approval mechanism (Lookaround). In this case, the negative statement forward is perfect ( Negative Lookahead ):

 /\d(?!$|\n)/ 

I do not know how it works in Sublime, but it is fully consistent with the PCRE standard.

Here is an example on regex101 .