2

I have a several hundred thousand line XML file that is full of data I don't need. I'm looking for a way to bulk delete thousands of irrelevant lines and am aware this can be done through find-and-replace with a regex. But my regex skills are basically non-existent.

The file is XML compliant so every line starts and ends with tags. An example block that recurs hundreds of times throughout the document is:

<g:payment_accepted>Visa</g:payment_accepted> <g:payment_accepted>Cash</g:payment_accepted> <g:payment_accepted>MasterCard</g:payment_accepted> <g:payment_accepted>Check</g:payment_accepted> <g:payment_accepted>WireTransfer</g:payment_accepted>

So in this instance I want a regex to search for instances:

<g:payment_accepted>WILDCARD_ANYTHING_IN_BETWEEN</g:payment_accepted>

Once I have a working regex I understand, I can tweak it for other repeated tag blocks in the document. No idea where to start though.

  • Ah I've just gone and worked it out, easier than I thought it would be, this does the trick ^(<g:payment_accepted>).*(</g:payment_accepted>)$ – Josh Bethell Nov 27 '18 at 17:00
  • 4
    Welcome to Super User! Feel free to post that as an answer :) – bertieb Nov 27 '18 at 17:08
0

You can just put .* wherever you want to allow anything. the caret at the beginning marks the start of a line and the dollar sign at the end represents the end of a line.

^<g:payment_accepted>.*</g:payment_accepted> $

(Putting the OP’s comment into an answer to make the solution easier to find.)

  • This is a copy of OP's comment. At least give them a credit or best, make this answer a community wiki. – Toto Nov 22 '19 at 11:35
  • @Toto thanks I did that. I wanted the answer to be easier to find. – Math Man Nov 22 '19 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.