The problem with this REGEX is that by default the .
does not include the \n
, this way would have to circumvent this lack, may be with denial [^...]
, that captures anything that is not in the group.
For your need you can do so: <(textarea)([^>]*)>([^%]*?)</\1>
.
See working in REGEX101
Explanation
<(textarea)
- capture literally <
and generates a literal group with textarea
, which will be used as a shortcut.
([^>]*)>
- will be all attributes of the tag, remembering that attributes do not have >
so I used his denial to take everything, finally should end with the tag ending >
.
([^%]*?)
- here is content to be captured, I used the denial of %
'cause I guess I won’t have it in the middle, but if I do, just switch to another character, for example ¬
, remembering that because it is denial includes any and all character that is not in the group including the \n
.
</\1>
- finally it should capture the end of the tag. that was resumed with the group 1 shortcut \1
.
Addendum
You can also use the flag s
to allow the .
(Dot) captures \n
.
by changing the REGEX to <(textarea)([^>]*)>(.*?)</\1>
.
Remembering that the frag should be applied s
.
Example JS
string.match(/<(textarea)([^>]*)>(.*?)<\/\1>/gs); // aqui foi necessário escapar o `/`, para não ser interpretado como fim da REGEX `<\/\1>`.
See working in REGEX101
Treating HTML with regex is difficult and sometimes the wrong tool. What environment/language are you working on?
– Sergio
@Sergio I’m using C#, but my doubt is only with the expression itself. I don’t use Regex to manipulate html, I use the html Agility pack. But we talked about it in chat, just wanted to bring the question to the site too.
– Randrade
Randrade, out of curiosity, had some bug in my answer?
– Sergio
@Sergio, you I replied in chat, but answering here too: Sorry, I would tell you here in chat the reason I forgot most. Your answer is perfect, you have no problem with it. I changed the acceptance only because the answer of the Guilhermelautert has a more didactic explanation on its part. I thought this would help you to seek. But I’m waiting for the time limit to offer a reward.
– Randrade
Okay, fine. His answer is bigger because regex is more complex :) I didn’t know you wanted to separate tags and content. Good content stays here in question and answers, nice.
– Sergio