I'm sure this is a pretty easy code for you but not being good with regular expressions - I've spent hours and not yet close to doing this.
Basically what I want is - to locate a word in a sentence and concatenate it using underscore with the word before that.
Egs - word to locate - "town"
Sentence - Where are pizza shops in George town.
output - Where are pizza shops in George_town.
Explanation - remove the white space character and replace it with underscore
Sentence - I heard in M. town the weather is great now.
output - I heard in M_town the weather is great now
Explanation - here we remove the DOT and space and joined them using underscore.
The idea is, once we find the word town, find the word before that and no matter what non alphanumeric character ( like apostrophe, single quote, double quote, space, double space, comma fullstop, hyphen) is in between - replace that character and join them using underscore.
If there are no words before town - make no changes.
Appreciate your help.