Is it possible to...



  • Take these two lines for example

    Contents Log Quantity 6 LastAccess 54200 END
    Contents Log Quantity 2 END

    using the search formula: Log Quantity\K.+(?= END)
    and the replace being, say 1000…

    can I NOT include the first line that says “LastAccess” from being replaced?

    so that it ends up being

    Contents Log Quantity 6 LastAccess 54200 END
    Contents Log Quantity 1000 END

    because that formula selects "6 LastAccess 54200 " as well as what I want to change…

    there must be some exclusion formula I can add in, right?



  • How about this one: (?<=Log Quantity )\d+(?! LastAccess)(?=.+END)

    See boost regex page for more information about RegEx syntax.



  • Hello, bill clinton and Gerdb42,

    If I refer to the original text, posted by bill clinton, below :

    https://notepad-plus-plus.org/community/topic/11716/help-with-formula-please/1

    it seems, that there are two spaces between the words Log and Quantity, as well as between the Qty number and the LastAccess string.

    So, rather that typing two spaces, we may use a SPACE, followed by the + quantifier ( identical to the syntax {1,}) )

    That comes to the regex :

    (?-i)Log +Quantity +\K\d+(?! +LastAccess)

    Notes :

    • You’ll notice that I did NOT use the following look-behind (?<=Log +Quantity +). Indeed it’s an invalid regular expression, because this regex may represent strings of different length ( due to the + quantifier )

    • It is important to notice that this restriction does NOT apply to look-aheads, as ( (?! +LastAccess) )

    • So, I replaced the look-behind with the \K construction. Thus, once, the regex has matched the regex Log +Quantity +,
      this string is forgotten and the regex engine match is reset to a zero length string !

    • Finally, the (?-i) modifier, at the beginning, forces the regex engine to perform a NON insensitive case search

    Best Regards,

    guy038


Log in to reply