0

I found many programs online to replace text in a string or file with words prescribed in a dictionary. For example, https://www.daniweb.com/programming/software-development/code/216636/multiple-word-replace-in-text-python

But I was wondering how to get the program to ignore certain parts of the text. For instance, I would like it to ignore parts that are ensconced within say % signs (%Please ignore this%). Better still, how do I get it to ignore the text within but remove the % sign at the end of the run.

Thank you.

nsoum
  • 129
  • 4
  • 1
    Stackoverflow isn't a code writing service, the community is fabulous at helping those that show they've made an effort and are stuck on specific issues. Can you show what you've tried and what isn't working? – AChampion Feb 20 '16 at 23:19
  • 1
    It sounds like you might benefit from using an if / else function, probably using Regex also. Maybe start here: http://stackoverflow.com/q/16720541/896802 – samthebrand Feb 20 '16 at 23:20

2 Answers2

1

This could very easily be done with regular expressions, although they may not be supported by any online programs you find. You will probably need to write something yourself and then use regex as your dict's search key's.

Good place to start playing around with regex is: http://regexr.com

Gasper
  • 5,679
  • 1
  • 18
  • 21
1

Well in the replacing dictionary just have any word you want to be ignored such as teh be replaced with the but %teh% be replaced with teh. For the program in the link you could have

wordDic = {
    'booster': 'rooster',
    '%booster%': 'booster'
}
timgeb
  • 76,762
  • 20
  • 123
  • 145
  • Also just as a note for the OP as I cannot comment on his post yet. @nsoum –  Feb 22 '16 at 23:10