mskov commited on
Commit
9aec1b9
1 Parent(s): 064e1b6

Update replace_explitives.py

Browse files
Files changed (1) hide show
  1. replace_explitives.py +7 -3
replace_explitives.py CHANGED
@@ -29,12 +29,16 @@ def sub_explitives(textfile, selection):
29
  target_word = []
30
 
31
  print("selection:", selection, "target_word:", target_word)
 
32
 
33
  if target_word:
34
  print("target word was found, ", target_word)
35
  print(textfile)
36
- pattern = r"\b" + re.escape(target_word) + r"\b" # Create a regex pattern for each word
37
- # textfile = re.sub(target_word, replacetext, textfile, flags=re.IGNORECASE)
38
- textfile = re.sub(pattern, replacetext, textfile, flags=re.IGNORECASE)
 
 
39
 
 
40
  return textfile
 
29
  target_word = []
30
 
31
  print("selection:", selection, "target_word:", target_word)
32
+ lines = textfile.split('\n')
33
 
34
  if target_word:
35
  print("target word was found, ", target_word)
36
  print(textfile)
37
+ for i, line in enumerate(lines):
38
+ for target_word in target_words:
39
+ pattern = r"\b" + re.escape(target_word) + r"\b"
40
+ # textfile = re.sub(target_word, replacetext, textfile, flags=re.IGNORECASE)
41
+ lines[i] = re.sub(pattern, replacetext, lines[i], flags=re.IGNORECASE)
42
 
43
+ textfile = '\n'.join(lines)
44
  return textfile