0

I have a xml file with repeated xml tags where I want to trim the string length to 10 characters

Data:

<Item>
<ItemNumber>1</ItemNumber>
<Description>Lorem Ipsum Lorem Ipsum</Description>
</Item>
<Item>
<ItemNumber>2</ItemNumber>
<Description>Ipsum Lorem</Description>
</Item>

Expected Result after trimming <Description> tag to 10 character:

<Item>
<ItemNumber>1</ItemNumber>
<Description>Lorem Ipsu</Description>
</Item>
<Item>
<ItemNumber>2</ItemNumber>
<Description>Ipsum Lore</Description>
</Item>

2 Answers 2

1

Press Ctrl+H, and enter the following:

  • Find what: (<Description>.{10})(.+?)(</Description>)
  • Replace with: $1$3
  • Select Regular expression, then click Replace All.

IMG:

1

Another way to go, without capture groups that slow down the process:

  • Ctrl+H
  • Find what: <Description>.{10}\K.+?(?=</Description>)
  • Replace with: LEAVE EMPTY
  • CHECK Match case
  • CHECK Wrap around
  • CHECK Regular expression
  • Replace all

Explanation:

<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

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .