Python Forum
Matching whole words in find/replace script
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Matching whole words in find/replace script
#1
I use the code below through Notepad++ but I cannot make it match whole words

with open('C:/Temp/Substitutions.txt') as f:
    for l in f:
        s = l.split()
        editor.replace(s[0], s[1])
I also tried:

editor.pyreplace(r'\b' + s[0] + r'\b', s[1])
and

editor = re.sub(r'\b' + s[0] + r'\b', s[1], editor)
Reply


Messages In This Thread
Matching whole words in find/replace script - by greektranslator - Jul-10-2017, 07:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  find and group similar words with re? cartonics 4 765 Oct-27-2023, 05:36 PM
Last Post: deanhystad
  package script cant find sibling script when executed from outside Bock 3 905 Mar-03-2023, 04:26 PM
Last Post: snippsat
  Working with Excel and Word, Several Questions Regarding Find and Replace Brandon_Pickert 4 1,601 Feb-11-2023, 03:59 PM
Last Post: Brandon_Pickert
  Find and Replace numbers in String giddyhead 2 1,257 Jul-17-2022, 06:22 PM
Last Post: giddyhead
  Regular Expression for matching words xinyulon 1 2,199 Mar-09-2022, 10:34 PM
Last Post: snippsat
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 2,852 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  Find and replace in files with regex and Python Melcu54 0 1,864 Jun-03-2021, 09:33 AM
Last Post: Melcu54
  find an replace not in all entries Monsterherz 1 1,959 Mar-01-2021, 03:59 PM
Last Post: BashBedlam
  Trying to find first 2 letter word in a list of words Oldman45 7 3,785 Aug-11-2020, 08:59 AM
Last Post: Oldman45
  Find and replace to capitalize with Regex hermobot 2 2,543 Mar-21-2020, 12:30 PM
Last Post: hermobot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020