Issue
I am porting some codes created using tkinter. It is some find and replace based on reg expression.
def replace():
text_editor.replace('1.0', 'end', re.sub("\d+", '<number>', text_editor.get('1.0', 'end')))
text_editor.replace('1.0', 'end', re.sub(r'([A-Z][a-zA-Z]*[A-Z]|(?:[A-Z]\.)+)', 'Acronymn', text_editor.get('1.0', 'end')))
What is in pyqt5 equivalent for text_editor.replace, text_editor.get ('1.0', 'end'). How to find and replace regex patterns using pyqt5?
Solution
You should not look for equivalent functions but understand what each piece of code does and then build the logic using the other technology.
In this text_editor.get ('1.0', 'end')
you get all the text so if you are using QTextEdit then you should use text_editor.toPlainText()
.
The same as text_editor.replace('1.0', 'end', ...)
whose task is to replace all the text so it must be replaced with text_editor.setPlainText()
.
text_editor.setPlainText(re.sub("\d+", '<number>', text_editor.toPlainText()))
text_editor.setPlainText(re.sub(r'([A-Z][a-zA-Z]*[A-Z]|(?:[A-Z]\.)+)', 'Acronymn', text_editor.toPlainText()))
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.