我有一个带有重复 xml 标签的 xml 文件,我想将字符串长度修剪为 10 个字符
数据:
<Item>
<ItemNumber>1</ItemNumber>
<Description>Lorem Ipsum Lorem Ipsum</Description>
</Item>
<Item>
<ItemNumber>2</ItemNumber>
<Description>Ipsum Lorem</Description>
</Item>
<Description>
将标签修剪为 10 个字符后的预期结果:
<Item>
<ItemNumber>1</ItemNumber>
<Description>Lorem Ipsu</Description>
</Item>
<Item>
<ItemNumber>2</ItemNumber>
<Description>Ipsum Lore</Description>
</Item>
答案1
答案2
另一种方法是不使用捕获组来减慢进程:
- Ctrl+H
- 找什么:
<Description>.{10}\K.+?(?=</Description>)
- 用。。。来代替:
LEAVE EMPTY
- 查看 相符
- 查看 环绕
- 查看 正则表达式
- Replace all
解释:
<Description> # literally, opening tag
.{10} # 10 any character
\K # reset match, forget all we have seen until this position
.+? # 1 or more any character, not greedy
(?=</Description>) # positive lookahead, make sure we have the closing tag after
截图(之前):
截图(之后):