0

I want to know if there's a way I can duplicate characters that's part of a single line without duplicating the whole line, using regular expression, and add them to the beginning of a line, that way I won't have to do it manually and risk causing error.

I want to be able to replace values like this

pl=100
pr=100
pj=100
bl=100
br=100

With this

pl=pl=100
pr=pr=100
pj=pj=100
bl=bl=100
br=br=100

Essentially copying the first three characters and adding them to the beginning of the line in this case.

1

I'd just use this regexp:

^(...)(.*)$

this is to duplicate the first 3 characters, if you want to duplicate anything up to and including the first character "=", use:

^([^=]=)(.)$

with the replacement string for both cases:

\1\1\2

Tested here: https://regex101.com/r/pK7xN3/1

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.