Search code examples
beyondcomparebeyondcompare4

BeyondCompare ignore content between opening and closing tags of modified tags


I saw in another article that BeyondCompare can't ignore line breaks (or at least couldn't at the time) so I assume this is a lost cause. However, we have a few hundred files that we've replaced tags in the files (example: {my_tag}some content{/my_tag} has changed to {new_tag}some content{/new_tag}. In some cases, the first tag + content could have only been 5lines and the new tag + content is 10lines. Is it possible to ignore these changes?

I tried {my_tag((.|\n)*){\/my_tag(.*) which seemed to work in regex101, but I get errors when trying to put that in BeyondCompare.

Thanks for any help.


Solution

  • If you're ignoring all instances of {my_tag}..{/my_tag} and {new_tag}..{/new_tag} and the content within them, you can do that as a grammar element as part of the file format, rather than using the "Unimportant Text" section of the Session Settings dialog (where the regex is limited to a single line).

    If you don't have a custom file format for the files yet, you'll need to create a new one first. If you do, skip to step 6. Apologies in advance for how many steps this is; the UI needs a redesign.

    1. Go to Tools > File Formats...
    2. Click the [+] button on the bottom of the list to the left and select "Text Format"
    3. On the "General" tab add a mask that matches your filenames, like *.csv.
    4. Click "Save As" to give it a name, then click "Close" to save all the changes.
    5. If you already have your files loaded, you'll need to select the new File Format from the "Format" dropdown on the toolbar. You can tell if it's correct if you see the File Format name in the panel immediately above the comparison edits.

    Once the file format is set up in the system and you have it loaded for your files:

    1. Click the "Format" button the toolbar to edit the currently loaded file formats.
    2. On the Grammar tab click the [+] button below the top listbox.
    3. In the "Grammar Item" dialog,
      a. Give the element a name like "Ignored tags"
      b. Change the "Category" to "Delimited"
      c. In "Text from" enter {(my|new)_tag} and in "to" put {/(my|new)_tag}
      d. Check the "Regular expressions" option.
      e. "Match character case" affects whether the search strings are case sensitive or not. "This element is case sensitive" controls whether differences in case between the two sides are treated as an important difference.
      f. Click "Ok"
    4. Click "Ok" in the outer "Text Format" dialog. At this point BC should ask if you want to reload the file format, which you should do. Once it's done, you can click on one of the tags and you should see the name you gave it in the status bar immediately below the edit (next to the horizontal scrollbar)
    5. Click the "Rules" toolbar button which will open the "Session Settings" dialog.
    6. On the "Importance" tab, uncheck the "Ignored Tags" item (or whatever you named it) in the bottom listbox.
    7. If you want to ignore it for all cases going forward, change the combobox at the bottom of the dialog from "Use for this view only" to "Also update session defaults". If you don't do that you'll need to repeat steps 10-13 whenever you want to ignore the tags.
    8. Click "Ok". The comparison should reload and the results should be blue as an unimportant difference.

    Once all of that is set up, it should work automatically going forward, and if you need it, you can add syntax highlighting for the element in the Options dialog under "Colors, Fonts".