No announcement yet.

Using Regex Grammar rules to ignore lines with text

  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Regex Grammar rules to ignore lines with text


    I have an issue with the BC regex engine used for the grammar rules.

    When I compare .c files, I don't want it to classify as unimportant any comment which contains a predefined keyword or keywords

    For example,
    /* This is a comment, it's not important */
    /* ABC This is a single line precompilation directive, it's important */
    /* ABD This is another single line precompilation directive, it's important */

    So the characters ABC and ABD are important.

    The default config for beyond compare has it classify as a comment anything from /* to */ which would classify my directives as unimportant differences. This is why I need to change the rule somehow to ignore any line with the letters ABC or ABD as per the structure of my previous example without losing the ability to hide regular comments which are indeed unimportant.

    I can manage this easily with the regex engine used in the search feature, but as I understand, this is not the same engine as the regex used for the grammar feature. A such, I can't use any lookahead regex functionality.
    If I could, I could write something like this

    What expression could I used to classify comments as being anything from /* to */ that does NOT containt the keyword ABC or ABD positioned as in my example

    This is driving me crazy haha.

    Thanks for the help

  • #2

    You would need to use multiple grammar elements. The list is semi-priority based:
    /* delimited to */

    The /\*.*ABC.*\*/ grammar would match first, and can be Important, while at the bottom it would match on the grammar elements. The issue is that the list is not absolutely priority based, and might match on a lower element. How does this work for your specific files?
    Aaron P Scooter Software


    • #3
      Thanks Aaron for the quick reply.

      I could have sworn that I had tried that already but this time it worked.

      I can identify any string that matches /\*.*AB(C|D).*$ as being a compiler directive and then the following priority grammar statement simply looks for a comment delimited by /* and */ as you said.

      The compiler directive gets labeled as such and then does not get relabeled as a comment.

      Works like a charm!

      As I made sure that they are both the lowest priority grammar rules, no chance of any mix up.


      Thanks for the quick and accurate response.

      Also, if you guys ever do update your regex parser, I would love to see lookaround functionality added in.