3

For example i have this text:

select * from T1 ;

select * from T2 ;

select * from T3 ;

My objetive is replace the text by this other:

select * from T1_H ;

select * from T2_H ;

select * from T3_H ;

when i looking for the regexp, i put the next: "from .* ; , but i whant replace only the part ".*" with the same text that has before plus "_H". How could i do this?

1 Answer 1

3

You need to group the part of the matching string so you can refer to it in the replacement.

Here are a couple of ways to do this:

  1. replace \(from\ \w*\b\) with \1_H: here \1 refers to the first group (the part between brackets). \b refers to the end of word (the place between T1 and the space in your example).
  2. replace from\ \w*\b with \&_H: here \& refers to the complete matched string.
2
  • Excellent explanation @juancho. The only missing piece is the meaning of \w*
    – Dox
    Commented Feb 8, 2017 at 7:32
  • Basic regular expressions for emacs are explained in the manual.
    – Juancho
    Commented Feb 8, 2017 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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