I'm trying to use egrep_replace to scan a series of string and replace certain words in certain contexts. However, regex isn't my strong point and I can't get it to work.
If my the word I want to replace is 'cat' with 'mouse' but preserving some of the surrounding characters if they are allowed.
examples:
1: "a cat box" should give "a mouse box"
2: "a cat, box" -> "a mouse, box"
3: "a x.cat box" -> "a x.mouse box"
4: "a x.cat, box" -> "a x.mouse, box"
5: "a bigcat box" -> "a bigcat box"
6: "a catnap box" -> "a catnap box"
so if my target word has a space or dot before and a space or comma after then it should be replace preserving the characters before and after.
I've read a few online tutorials about regex, but still can't seem to make this work no matter what I try.
If my the word I want to replace is 'cat' with 'mouse' but preserving some of the surrounding characters if they are allowed.
examples:
1: "a cat box" should give "a mouse box"
2: "a cat, box" -> "a mouse, box"
3: "a x.cat box" -> "a x.mouse box"
4: "a x.cat, box" -> "a x.mouse, box"
5: "a bigcat box" -> "a bigcat box"
6: "a catnap box" -> "a catnap box"
so if my target word has a space or dot before and a space or comma after then it should be replace preserving the characters before and after.
I've read a few online tutorials about regex, but still can't seem to make this work no matter what I try.