1

I need to process a xml file, in which a certain text has to be inserted (duplicated) - see the following, for an example:

<Item Property1="..." ... PropertyN="someText"></Item>

How I want it to look:

<Item Property1="..." ... PropertyN="someText">someText</Item>

The someText

  1. doesn't have a fixed length (1 or more sentences/words)
  2. can/may contain the followings:
    • &# xD; &# xA
    • (& amp; and _)
    • {0}{1}
    • /\~!@#%&*_+

My questions:

  1. I've managed to find some of the groups (i.e. the text before PropertyN (^.*?PropertyN=") and the last group (i.e the one containing "> < /Item>" - \"></Item>.*$)) but I don't know how to extract the PropertyN value, how to integrate it and how to duplicate it.

  2. How can I change the (replace with) regex so that a prefix and/or a suffix (constant in the entire file) are added for each copy of the someText? (for example I want "###prefix" and "###suffix" to be added so that the line looks like this)

    <Item Property1="..." ... PropertyN="someText">###prefixsomeText###suffix</Item>

Thank you!

R

1 Answer 1

1
  • Ctrl+H
  • Find what: <Item Property1=.+? PropertyN="([^"]+)">\K
  • Replace with: ###prefix$1###suffix
  • CHECK Match case
  • CHECK Wrap around
  • CHECK Regular expression
  • UNCHECK . matches newline
  • Replace all

Explanation:

<Item Property1=    # literally
.+?                 # 1 or more any character, not greedy
PropertyN="         # literally
([^"]+)             # group 1, 1 or more any character that is not double quote
">                  # end tag
\K                  # forget all we have seen until this position

Replacement:

###prefix           # prefix
$1                  # content of group 1, (some text)
###suffix           # suffix

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 .