Announcement

Collapse
No announcement yet.

Ignore prefix on word

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ignore prefix on word

    Hi!

    I've seen the posts about ignoring a line with a certain prefix, but what I wan't to do is ignore the starts of word that have a certain prefix.

    For example I may want to compare the follwing lines and ignore those two lines

    Code:
    FOOTest = 1;
    MyStruct.Test = FOOAnotherValue;
    to compare with:

    Code:
    BARTest = 1;
    MyStruct.Test = BARAnotherValue;
    Is it possible to ignore both of those lines ?

    Thanks

  • #2
    If you know what the prefix will be on either side, you can use replacements.

    If you don't know which prefix will show up on each side, you can create a basic regular expression
    grammar rule under Session -> Session Settings... -> Importance tab.

    @smsisko:
    The simplest Regular Expression grammar rule would be:
    FOO|BAR

    Set the grammar rule as unimportant. Make sure you select "Also update session defaults" in the drop-down before clicking OK if you want the rule to be in effect for other files as well.

    The | serves as an "OR" clause. You can include as many prefixes as you like so long as you separate them with | symbols.
    @Scooter:
    Why doesn't the following basic Regular Expression grammar rule work?
    \bFOO\w+|\bBAR\w+

    It works for a regular expression find operation, but fails in a grammar rule set as unimportant.
    What this regular expression should do:

    \b ensures that you are starting at the beginning of a word. This will make sure that you only match a prefix and not, for example, the BAR in MyBARStruct or the FOO in MyFOOStruct as shown below:
    BAR
    BARTest = 1;
    MyBARStruct.Test = BARAnotherValue;

    FOO
    FOOTest = 1;
    MyFOOStruct.Test = FOOAnotherValue;

    The \w+ ensures that there is at least one additional word character following the prefix. This would not match FOO and BAR on their own, for example, since they don't prefix a larger word.
    Last edited by Michael Bulgrien; 12-Feb-2011, 11:45 AM.
    BC v4.0.7 build 19761
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Comment


    • #3
      I got this replacement (PRO-feature) work:

      Left = "(^|\s)FOO([^\s$])" Right = "$1BAR$2"

      (^|\s): Start of line or whitespace character before FOO
      ([^\s$]): Neither whitespace character nor end of line behind FOO
      $1: Anything from left before FOO
      $2: Anything from left behind FOO

      Colors are exactly like Michaels example (I just compared those via clipboard, FOO on the left and BAR on the right).

      Greetings Lutz

      Comment


      • #4
        Thanks for the example, Lutz. The reason I used \b instead of ^|\s is that \b will break on any non-word character or punctuation (anything other than an alphanumeric or underscore). Your code would not interpret the following, for example, in the same way that using \b would:
        FOO.BAR@FOOBAR.COM

        BAR.FOO@BARFOO.COM
        Last edited by Michael Bulgrien; 12-Feb-2011, 02:36 PM.
        BC v4.0.7 build 19761
        ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

        Comment


        • #5
          I haven't found \b supported by BC (neither help nor RE dropdown lists), so I only used the documented.

          The replacement (\b)FOO([^\b])=$1BAR$2 gets the same result as mine.
          Your eMail-example shows (in both replacement versions) Aligned Details as attached.

          Greetings Lutz

          Comment


          • #6
            That is my issue with BC3. Regular expressions that work fine in find operations don't necessarily work in grammar rules and replacements. If you Search->Find... on the regular expression:
            \bFOO\w+|\bBAR\w+
            You will notice that it finds FOOBAR and BARFOO in my sample lines above, and nothing else. So the regular expression works fine there. But putting the exact same regular expression in an unimportant grammar rule fails to make FOOBAR and BARFOO unimportant.
            Last edited by Michael Bulgrien; 12-Feb-2011, 02:56 PM.
            BC v4.0.7 build 19761
            ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

            Comment


            • #7
              Hello Michael and Lutz,

              Thanks for the example cases in using Text Replacements.

              @Michael, The grammar technically uses a lexer which only supports a subset of the regular expression language. Find, Replacements, etc all support the full regular expression language.
              Aaron P Scooter Software

              Comment


              • #8
                Aaron, I don't care so much about replacements, but please enhance BC3 to support a fuller subset of the regular expression language in grammar rules. For anyone that uses regular expressions on a regular basis, it is extremely frustrating to have basic regex coding fail in grammar rules.
                BC v4.0.7 build 19761
                ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

                Comment


                • #9
                  Has updating or replacing the lexer with something more competent in regular expressions been added to the customer wish list? This particular item is very important to me.
                  BC v4.0.7 build 19761
                  ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

                  Comment


                  • #10
                    Yes, it is on our Wishlist, but is a very large project and won't be able to be tackled soon.
                    Aaron P Scooter Software

                    Comment

                    Working...
                    X