Loading ...
Sorry, an error occurred while loading the content.

22505RE: [NTB] Regular Expression: find between two words

Expand Messages
  • John Shotsky
    Feb 29, 2012
      I'm probably getting into this late, but I'm not understanding the problem exactly. I would implement this slightly
      differently though.

      If these are the strings: (Notice the extra spaces in the top one)
      word1 some text here word2
      word1 some text here word2

      I would use this:
      ^!Replace "\bword1\b\K[^\r\n]*(?=\x20word2\b)" >> "" AIRSW
      Which removes everything between word1 and [sp]word2, leaving this:
      word1 word2

      The \b identifies word breaks, preventing partial matches with larger words. All preceding \K is kept. Everything
      preceding [sp]word2 is removed as unwanted. Not sure why an assertion would be used on the first part. Is there a reason
      for doing it that way?

      RecipeTools Web Site: http://recipetools.gotdns.com/

      From: notetab@yahoogroups.com [mailto:notetab@yahoogroups.com] On Behalf Of Eb
      Sent: Wednesday, February 29, 2012 05:17
      To: notetab@yahoogroups.com
      Subject: Re: [NTB] Regular Expression: find between two words


      James reports, that the expression

      "(?<=word1 )[^\r\n]*(?= word2)"

      fails to find " some text here "
      (containing a double space on the left.

      Tests on my PC confirm this bug.

      Are you saying, YOUR NoteTab succeeds in finding the pattern?

      That would imply the bug being INCONSISTENCY rather than regular expression handling.

      On TWO of _my_ systems, NoteTab FAILS to find the double space pattern. This implies, that somewhere between finding the
      first space in the assertion, and the second space, NoteTab loses track of spaces.


      --- In notetab@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
      > --- In notetab@yahoogroups.com, "Eb" <ebbtidalflats@> wrote:
      > > ... NoteTab is confused here.
      > There is no "interpreting the two spaces as one" here. NT is exactly following PCRE rules: The Lookbehind is matching
      the first space after 'word1', and the Character Class '[^\r\n]' matches the second space following 'word1'.

      > > --- In notetab@yahoogroups.com, "book7reader" <jim@> wrote:
      > > >
      > > > If this is the actual target text:
      > > >
      > > > word1 some text here word2

      > > > (?<=word1 )[^\r\n]*(?= word2)

      > It does not find " some text here "
    • Show all 10 messages in this topic