[PROBLEM] How can I write Tkinter reg. expression to fetch the string after a word ?
[INPUT]
def addCutOffFromButton():
fieldText = afterCutOff.get()
searchText = '[cut\-off:.*]'
replaceText = 'cut-off:' + str(fieldText)
startPosition = textPad.search(searchText, "1.0", stopindex=END, regexp=True)
print "startPosition", '{!r}'.format(startPosition)
print len(searchText)
if startPosition:
endPosition = '{}+{}c'.format(startPosition, len(searchText))
print "endPosition", '{!r}'.format(endPosition)
textPad.delete (startPosition, endPosition)
textPad.insert (startPosition, replaceText)
else:
textPad.insert(END+'-1c', '\n' + 'cut-off:' + str(fieldText))
[OUTPUT]
This code will replace: "cut-off: xyz" if:
- there is no text before "cut-off: xyz"
- there is text before "cut-off: xyz" but that text does not include the chars from "cut-off: xyz"
[DESIRED] - the code should replace "cut-off: xyz" regardless of its position
[NOTE] - If i replace the reg exp with static string ("cut-off"), then I will not face any problems - python regular expression: "(cut-off.*)" will not deliver expected output