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

Re: Searching variables with regex?

Expand Messages
  • Sheri
    ... I have no idea about the rest of it, but if you put the cursor at beginning of the file and execute this clip repeatedly until you get No More Matches, it
    Message 1 of 35 , Oct 3, 2010
      --- In ntb-clips@yahoogroups.com, "Paul" <xboa721@...> wrote:
      >
      > Hi,
      > Who's up for a challenge? (HELLLLLPPPPPP!!!)
      >
      > I'd like to search a text file for curly delimited brackets, that may also be nested. I would then like to save the contents within the brackets to a variable and subsequently run a routine on the variable, searching preferably using regex code.
      >
      > Is this possible within NTP or do I need to resort to Perl for something this complex?
      >
      > e.g. {term one|term two} or {term A{term B|term C}}
      > A simple ^!Find using the R switch gets the innermost bracketed term. My :LabeledSubroutine can then work out which term, term B or term C, to use and 'pass it back' somehow. Then the :LabeledSubroutine should get a variable "term A term B" or "term A term C" depending on the subroutine algorithm.
      >
      > Alternatively the :LabeledSubroutine could be designed to process the entire nest of search terms first by numbering the terms $1, $2, etc. and then have some sensibility about where the nesting occurs.
      >
      > Before I delve into hard coding - i've written the basic pseudocode - and it looks like I may have to resort to a dedicated programming language. However, my gut feeling is that NTP can probably do this.
      >
      > A couple of pointers to commands and functions to tackle this would be helpful or a simple 'go learn Perl' if that's best.
      >
      > Thanks in advance.
      > Paul
      >

      I have no idea about the rest of it, but if you put the cursor at beginning of the file and execute this clip repeatedly until you get No More Matches, it seems to locate the content of each matching pair of curly braces in the file (whether nested or not), outer to inner.

      ^!Find "\{(([^{}]++|(?R))*)\}" RS1
      ^!IfError Next Else Skip
      ^!Prompt No More Matches
      ;end of clip

      I tried it with NTP 6.2.

      The pattern is adapted from one in the Regular Expressions help file (regex.chm) in the section titled Recursive Patterns.

      Regards,
      Sheri
    • Paul
      See? There s always someone ready to apply the rules even when I thought I was doing something harmless?!! sry bout that.. point taken. will visit
      Message 35 of 35 , Oct 11, 2010
        See? There's always someone ready to apply the rules even when I thought I was doing something harmless?!! <ahem> sry 'bout that.. point taken. will visit over there.....

        --- In ntb-clips@yahoogroups.com, Axel Berger <Axel-Berger@...> wrote:
        >
        > Paul wrote:
        > > I only stiffly object to copied work when it is purported to be
        > > ones own work. In the early stages of professional development
        > > I advocate reprimand and retraining.
        >
        > This is beginning to drift off the topic od clips, My answer certainly
        > is, which is why I just posted it to the off-topic list.
        >
        > Axel
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.