Ajay Jain
Ajay Jain

Reputation: 93

Removing line breaks after fixed length

I have a text file with thousands of XML strings on each line. However, if any XML string exceeds 32767 characters, then the remaining text is moved to next line. I need to remove such line breaks to ensure each line has a complete XML string.

Sample version of the file content having line break after 55 characters is as follows:

<?xml version="1.0" encoding=""?><Policy></Policy>
<?xml version="1.0" encoding=""?><Policy></Policy>
<?xml version="1.0" encoding=""?><Policy>111111111111<
/Policy>
<?xml version="1.0" encoding=""?><Policy></Policy>
<?xml version="1.0" encoding=""?><Policy>2222222222222
</Policy>
<?xml version="1.0" encoding=""?><Policy><A></A>333333
33333</Policy>

The output is expected to be as follows:

<?xml version="1.0" encoding=""?><Policy></Policy>
<?xml version="1.0" encoding=""?><Policy></Policy>
<?xml version="1.0" encoding=""?><Policy>111111111111</Policy>
<?xml version="1.0" encoding=""?><Policy></Policy>
<?xml version="1.0" encoding=""?><Policy>2222222222222</Policy>
<?xml version="1.0" encoding=""?><Policy><A></A>33333333333</Policy>

Please suggest how this can be done in Notepad++

Upvotes: 0

Views: 283

Answers (1)

Toto
Toto

Reputation: 91518

  • Ctrl+H
  • Find what: \R(?!<\?xml)
  • Replace with: LEAVE EMPTY
  • CHECK Match case
  • CHECK Wrap around
  • CHECK Regular expression
  • Replace all

Explanation:

\R              # any kind of linebreak
(?!<\?xml)      # negative lookahead, make sure we haven't "<?xml" after

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

Upvotes: 1

Related Questions