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

Re: [Clip] Brooding about ^$GetDocMatchAll

Expand Messages
  • Sheri
    Hi Alec, Flo, Assuming that in reality you would use one or more variables in the regular expression to convey the keyword(s) there are two concerns: 1. that
    Message 1 of 35 , Jan 10, 2007
    • 0 Attachment
      Hi Alec, Flo,

      Assuming that in reality you would use one or more variables in the
      regular expression to convey the keyword(s) there are two concerns:

      1. that anything in the keywords that looks like a metacharacter get
      escaped somewhere along the line (or keywords surrounded by \Q..\E)

      2. that the resulting regular expression be tested before it is
      executed, e.g.,

      ^!IfRegexOk Pattern GoToLabelTrue [ELSE GoToLabelFalse]

      I have constructed regex'es using variables holding lists of
      alternates which failed because the resulting regular expression was
      "too long". I was never able to pin down what caused mine to be too
      long (it evidently meets a limitation of the underlying regex engine
      or the "stack space" allotted), but it seemed to happen to me when the
      regexp with expanded variables was somewhere around 15K in size.

      So my conclusion is, its best to test with IfRegexOk before using a
      regular expression (unless it uses only literals and metacharacter you
      have previously tested yourself) and have a backup plan for when it fails.

      Regards,
      Sheri

      --- In ntb-clips@yahoogroups.com, buralex@... wrote:
      >[...]
      > H=71-10 Concordance-Jonas
      > ;Alec Burgess 2007-01-10
      > ; set input buffer to: original: a b c d K2 e f g K3 h i j k K2 l m n
      > K4 o p q r
      > ^!setlistdelimiter ^p
      > ^!replace "((?:\w+\s+){2})(K1|K2|K3|K4)" >> "$1=$1$2" rwsai
      > ^!replace "(K1|K2|K3|K4)((?:\s+\w+){3})" >> "$1$2+$2" rwsai
      > ^!set theConcordance=^$GetDocMatchAll("(?<==)(?P<conCord>.*?)(?=\+)";1)$
      > ^!select ALL
      > ^%theConcordance%
      >
      > gives this as output
      > c d K2 e f g
      > f g K3 h i j
      > j k K2 l m n
      > m n K4 o p q
      >
      >[...]
    • jonas_ramus
      ... Sheri, thanks - I should have noticed that by myself! With another r n it s perfect now. ... That s it! Those who don t want to remove these spaces may
      Message 35 of 35 , Jan 17, 2007
      • 0 Attachment
        --- In ntb-clips@yahoogroups.com, "Sheri" <silvermoonwoman@...> wrote:
        >
        > Hi Flo,
        >
        > There should only be one difference between the two replace commands
        > (inclusion or exclusion of the \b's) but the second one is missing
        > the critical \r\n

        Sheri, thanks - I should have noticed that by myself! With another
        \r\n it's perfect now.

        > You also might want to close up the spaces in the replacement
        > clause, they will create extra spaces in the output.

        That's it! Those who don't want to remove these spaces may define a
        left context with ^!Set %Char_left%, and a right context with ^!Set %
        Char_right%=^$Calc(^%Char_left%-2)$ in order to get the same size of
        context on both sides.

        Thanks again for all the help from Alec and you in developing this
        clip!

        Flo

        PS Get well soon with your cold!
      Your message has been successfully submitted and would be delivered to recipients shortly.