|
|||||||
![]() |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Junior Member
![]() Posts: 1
Karma: 10
Join Date: Dec 2020
Device: none
|
Find and replace first x instances of each word from a list of words
I'm trying to underline the first x instances of each word from a list of words (over 1000 words).
Using the Regex-function mode in the Editor Find/Replace I have been able to find and replace all instances of a word with: Code:
<u>word</u> This is the code I have that replaces all instances: Find: Code:
>[^<>]+< Code:
#create list of unknown words stored in a text file
import io
myfile = io.open("C:/Users/adame/Desktop/Python/unknown_words.txt", encoding="utf-8")
unknown_words = []
for line in myfile:
* * unknown_words.append(line.strip())
myfile.close()
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
* * replacestr = ""
* * for word in unknown_words:
* * * * replacestr = (replacestr + ".replace('" + word + "', '<u>' + '" + word + "' + '</u>')")
* * * * myreplace = "match.group()" + replacestr
* * return eval(myreplace)
Code:
.replace(unknown_word, '<u>' + unknown_word + '</u>') |
|
|
|
![]() |
| Tags |
| find, regex-function, replace |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| clear dropdown find and replace list? | pompano | Sigil | 8 | 10-09-2013 07:50 AM |
| MS Word Find & Replace and "Smart" quotes question. | Ahu Lee | Workshop | 1 | 01-14-2013 12:02 PM |
| Replace multiple matching instances within paragraph? | murphycc | Conversion | 2 | 02-23-2012 10:53 AM |
| Find/Replace Won't Find | Rand Brittain | Sigil | 7 | 09-24-2011 05:35 AM |
| Help with Word - Find & Replace | Big Kev | Workshop | 3 | 09-21-2010 07:51 PM |