I am trying to use the script below to find/replace a list of words, but I cannot manage to make it match whole words. Could you help?
with open('C:/fix.txt') as f: for l in f: s = l.split() editor.replace(s[0], s[1])
You could change to a regular-expression replacemement, and add a word-boundary assertion before and after your search term:
editor.rereplace(r'\b' + s[0] + r'\b', s[1])
Thank you very much!
Log in to post a comment.
I am trying to use the script below to find/replace a list of words, but I cannot manage to make it match whole words. Could you help?
You could change to a regular-expression replacemement, and add a word-boundary assertion before and after your search term:
editor.rereplace(r'\b' + s[0] + r'\b', s[1])
Thank you very much!