Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In my specific example, for a selection of lines I want to duplicate them inline, separated by an arbitrary marker

Ie,

stringA
stringB

becomes

stringA_something_stringA
stringB_something_stringB

Altough I'm mediocre with regex, I believe this should be accomplished by searching for something like:

(string.)_something_(string.)

and replacing with

\1_something_\1

However I'm unable to get even simple \1 replacements working. Am I doing something wrong?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Your replacement regex is correct, however your match will not work as there is only 1 world per line. You are trying to match the replacement text which is not yet there :)

try this:

(string.)

replace with \1_something_\1.

Make sure you are using regex mode as well.

share|improve this answer
    
Ty JohnT (and Sonny) for the answer. JohnT. I still don't follow why the search string doesn't work though. Even consdiering just one line (one world) I would have thought that "(string.)_something_(string.)" matches "stringA_something_stringA". –  RJFalconer Jan 28 '11 at 18:08
    
@RJF I thought you were replacing StringA and StringB with stringA_something_stringA and stringB_something_stringB ? In that case you cannot search for text that is not already there. –  John T Jan 28 '11 at 18:11
    
Oh, yeah. Confusing myself there. Tyvm. –  RJFalconer Jan 29 '11 at 9:06

Find what: (string.)
Replace with: \1_something_\1

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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