Question:
Regular Expression to replace characters in a word?
?
2011-08-07 07:08:38 UTC
I am looking for a regular expression that will replace will replace letters in a whole world. I am working on a script that will replace old english words with modern english words... like

He eateth the cow. become He eats the cow.

I cannot seem to get the expression for this. It needs to match whole words too...

Any help would be greatly appreciated.
Three answers:
McFate
2011-08-07 07:15:00 UTC
In most regex languages "\b" matches a word boundary. (But you didn't say exactly which language you are using, so I can't be 100% sure.)



So "\beat\b" matches "I don't know what to eat." But not "I'm beat."
.
2011-08-07 07:16:17 UTC
Sed has several commands, but most people only learn the substitute command: s. The substitute command changes all occurrences of the regular expression into a new value. A simple example is changing "day" in the "old" file to "night" in the "new" file:



sed s/day/night/ new



Or another way (for Unix beginners),



sed s/day/night/ old >new



and for those who want to test this:



echo day | sed s/day/night/
JoelKatz
2011-08-07 07:17:49 UTC
You can use \b to match a word boundary, so "\beateth\b" will match "he eateth the cow" but not "he seateth the dog".


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...