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

Re: [NTS] Finding Pairwise Matches

Expand Messages
  • flo.gehrke
    ... A single «[^ ,]*?» or even «[^,]+» (no need to escape comma in character class) would match that «yyyy» section but your RegEx is demanding
    Message 1 of 6 , Sep 30 8:31 AM
    • 0 Attachment
      --- In ntb-scripts@yahoogroups.com, Art Kocsis <artkns@...> wrote:

      > given: nnn,«yyyy»,,«x,xxx»,«yyyy»,,
      > the pattern: («[^\,]*?»)*.*?\K«(.*?)\,(.*?)»
      > matches: «yyyy»,,«x,xxx»
      >
      > Why does the "(«[^\,]*?»)*" NOT consume the "«yyyy»" and reset the
      > match point past it?

      A single '«[^\,]*?»' or even '«[^,]+»' (no need to escape comma in character class) would match that '«yyyy»' section but your RegEx is demanding more than that.

      In short, the engine starts testing '(«[^\,]*?»)*.*?\K«'. Your subject string, however, starts with 'nnn...'. So the engine doesn't achieve any submatch until it's testing '.*?\K«'. Now backtracking to '.' it matches 'nnn,«' because each character is matched with the dot. So 'nnn,' is not skipped, and it goes on till 'nnn,«yyyy»,,«x,xxx»' is matched in the end.

      BTW, for me, a simple clip like...

      ^!Jump Doc_Start
      :Loop
      ^!Find ""[^"]+"" RS
      ^!IfError End
      ^!IfMatch "[^,]+" "^$GetSelection$" Skip
      ^!InsertText ""^$StrReplace(,;;^$GetSelection$;A)$""
      ^!Goto Loop

      (designed for Ntb 7.0) would perfectly do the job (removing commas between opening and closing brackets) when run against your sample string...

      nnnnnnnnn,"xxxx",,,"ss,ss,",xxx
      nnnnnnnnn,"xx,xx",,"ss,ss",xxx
      nnnnnnnnn,xxxx,,"ss,ss,"xxx

      Even...

      ^!Jump Doc_Start
      ^!Find ""\w+,(\w|,)*"" RS
      ^!IfError End
      ^!InsertText ""^$StrReplace(,;;^$GetSelection$;A)$""
      ^!Goto Skip_-3

      would do it if there were no more variations (?) in the string.

      Members being at war with RegEx will be happy to see that they could even find a solution without any RegEx at all:

      ^!Jump Doc_Start
      :Loop
      ^!Find """ RS
      ^!IfError End
      ^!MoveCursor +1
      ^!Keyboard CTRL+M &50
      ^!IfFalse ^$StrPos(",";"^$GetSelection$";0)$ Skip
      ^!InsertSelect "^$StrReplace(",";"";"^$GetSelection$";A)$"
      ^!Jump Select_End
      ^!Goto Loop

      Regards,
      Flo
    Your message has been successfully submitted and would be delivered to recipients shortly.