da_steve101
da_steve101

Reputation: 283

Find and replace surrounding words in emacs

Consider the following:

The cat jumped over the wall
The cat sat on the wall
The cat strolled along the wall
The cat hid under the hedge
The horse considered the wall

I would like to replace "cat * wall" with "dog * bridge" in emacs resulting in:

The dog jumped over the bridge
The dog sat on the bridge
The dog strolled along the bridge
The cat hid under the hedge
The horse considered the wall

I know i can find replace just cat -> dog and accept each example but I am wondering how I can do it all automatically

Upvotes: 1

Views: 73

Answers (1)

da_steve101
da_steve101

Reputation: 283

Thanks @Barmar

The regex I was looking for was

cat \(.*\) wall -> dog \1 bridge

Upvotes: 1

Related Questions