I am new to regex.

I want to modify lines in a text file based on a particular pattern. I was able to write an expression to find the pattern but in the group of line that it returns I want to only replace one line and keep the rest as it is.

Here is an example:


I used the following expression to find this group with my text file


I want to only replace this line:


I am not sure how to write an expression that would keep the other line as they are.

Do you have any insight?


1 Answer 1


I found my answer, by using () in the search field and \ in the replace field.

For instance, to do what I wanted to do I would have used the following:

  • In the search field: (.*.)\r\n(.*.)\r\n(.*.)\r\n(.*.)
  • In the replace field: \1\r\n STRING TO BE CHANGED\r\n\3\r\n\4
  • We don't really mind people finding out answers themselves, whether it's 5 minutes or 5 years later. Self-answers are considered good and acceptable when they can help everyone. In a couple of days you should be able to accept your answer and thus mark this question as "complete".
    – Mokubai
    Jun 23, 2015 at 16:45
  • 2
    This is a pretty vague answer. Could you expand your answer to explain how to use the capturing group? I.e., provide the pattern and the replacement expression you used.
    – Excellll
    Jun 23, 2015 at 17:15

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.