Answer
As mentioned by the Wellington user, you should follow the steps:
Go to Search-> Replace.
Set the value of the Search/Find field: (<.*?(?=mensagem).*?>)(.*?)(<.*?>)|(.*)
Set the value of the Replace field to: 2 or $2.
Set the search mode to: Regular expression.
Click the button: Replace everything.
This will replace the entire text with content that has the keyword message within the tag.
You can test this regex here.
If you have not solved your problem comment here what you expected, what happened wrong and try to solve, I hope to have helped :D
Explanation by Regex
This regex has 4 groups of catches, I will explain what each one does so that I can better understand
(<.*?(?=mensagem).*?>)
The group 1 will capture everything that is between the tag, if you have the message word in any position before the character ">", for that I used a Positive Lookahead, it determines that everything between (?=
and )
is a condition for catching what is before.
(.*?)
The group 2 will only be triggered if group 1 captures something, since it is in the same expression and is not after an operator OR, it captures anything but line breaks and stops as soon as another character of the next expression is found.
(<.*?>)
The group 3 captures everything that is between the tags after group 2, the tag "<" also serves as a limiter for group 2 to stop capturing when they find it.
|(.*)
The group 4 is an expression that is after the operator OR, this means that if regex does not capture with the previous expression, it will try to capture with that, so just insert an operator "." to capture any character other than line break (\n
), then anything that does not match your search will be deleted by replacing everything with group content 2.
Which programming language you are using ?
– NoobSaibot
I am using Notepad++, more specific: Find, Find with the "regular expression" option selected.
– PTC man
Try the following:
<span[^>]+>(.*?)<\/span>
– NoobSaibot
See working here
– NoobSaibot
He is very close to this friend Wéllington. In the site regex101 he separates the text in Group 1, but in Notepad ++ he.
– PTC man
Recommended reading: https://stackoverflow.com/a/1732454/4438007
– Jefferson Quesado