regex - QRegularExpression - How to extract string from between two <ca> tags? -
I am trying to get the text in many tags as the following:
< Strong> Text file:
Internal auto-configured settings file ________________________________________ ((do not attempt to manually edit it)) ________________________________________ # Saved certificate: & lt; Ca & gt; Text that I want to remove & lt; / Ca & gt; ... & lt; Cert> Another lesson I want to remove & lt; / Cert & gt; ...
In my code I open the previous file and read its contents & amp; Store it in a QString
So far, I have done the following without any success:
QRegularExpression regex ("& lt; ca & gt; (. *) & Lt; / ca & gt; ", QRegularExpression :: MultilineOption); QRegularExpressionMatch match = regex.match (content); QString ca = match.captured (1); QDebug () & lt; & Lt; CA; QDebug () & lt; & Lt; "\ N \ nDone !!";
& lt; & Lt; & lt; Cert> I did the same for
, but I got an empty string for both.
Instead use QRegularExpression :: MultilineOption
. The problem is that
does not match the character of the new line in default mode.
Citing the document:
Dot Metaccharter (
.
) Pattern string is allowed to match any character in the subject string , Which includes Newline (usually, does not match dot newline). This option corresponds to/ s> modifier in Perl regular expression.
Be sure to
& lt; / Ca & gt;
The input is displayed only once.If that is not the case, change your expression slightly:
"
This creates the quintifier lazy (instead of the default greedy), and this closest tag matches
& lt; / ca & gt;
.
Comments
Post a Comment