I'm trying to perform some regex searches on a QTextEdit widget which has rich text format. Visually it displays properly but regex ignores the numerous <BR>
line breaks and sees the entire body of text as one large single line.
If I display the text as plain text and use \n
for new lines instead, regex search works perfectly interpreting each line as it's own line. However plain text as the name suggests has no rich text formatting which I need.
Is there anyway for regex to interpret an HTML line break as a new line instead of \n
or any way I can get regex to work properly with HTML? I tried adding <BR>\n
but that doesn't do anything.
I'm using QTextEdit.find( QRegExp ) with PyQT5 for Python.
Here's an example of what's happening:
Regex pattern: Lorem.+
Text body:
Lorem ipsum dolor sit amet.
Consectetur adipiscing elit.
sed do eiusmod tempor incididun
Expected match:
Full match 0-28 `Lorem ipsum dolor sit amet. `
Actual match:
Full match 0-89 `Lorem ipsum dolor sit amet.Consectetur adipiscing elit.sed do eiusmod tempor incididunt`
I don't think it's the issue of the dot matching everything including new line character because when use the exact same regex pattern in plain text mode using \n
as new lines the dot doesn't include new line characters too. This only happens when I set the text QTextEdit with HTML instead of plain text
and have it know the line ends there. – DonutPilot Jun 19 '18 at 15:11
but only the first line if I'm using plain text and \n as a line break. – DonutPilot Jun 19 '18 at 17:26
` or `
` tag. I ended up putting each line between div tags and that solved the new line character not appearing when using regex.