开发者

Aggregate regex replace

开发者 https://www.devze.com 2022-12-18 13:57 出处:网络
So this is purely a question of curiosity... Say I have a set of tags: <tag> <sub>A</sub>

So this is purely a question of curiosity...

Say I have a set of tags:

<tag>
  <sub>A</sub>
  <sub>B</sub>
  <sub>C</sub>
</tag>
<tag>
  <sub>1</sub>
  <sub>2</sub>
  <sub>3</sub>
</tag>

Is it possible to, in a single Regex.Replace command, aggregate the contents of all <sub> tags within a <tag> into one <sub>.

Like so:

<tag><sub>ABC</sub></tag>
<tag开发者_如何学Go><sub>123</sub></tag>

My guess is no, but I figured I'd give it a shot.


Is the theoretical tag set always this clean? If so, replacing </sub>\s+<sub> with nothing would do it.

0

精彩评论

暂无评论...
验证码 换一张
取 消