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

Re: Searching variables with regex?

Expand Messages
  • diodeom
    ... ;Locate a pair of solo or innermost brackets ^!Find {[^{}]++} WRS ;Leave the loop if no more found (presumably to ;the label which checks if another
    Message 1 of 35 , Oct 4, 2010
      Paul wrote:
      > (...)
      > In a document containing multiple lines it is easy to see how the number of permutations grows exponentially so rather than cycle through the combinations the subroutine chooses one term at random.
      >

      If simple randomization would suffice, you could get text from the "mother" file (e.g. with ^$GetFileText(FileName)$), paste it into a new doc (to be saved later) and run the loop which picks one and removes leftover alternatives working from the inside out:

      :Random
      ;Locate a pair of solo or "innermost" brackets
      ^!Find "{[^{}]++}" WRS
      ;Leave the loop if no more found (presumably to
      ;the label which checks if another doc is needed)
      ^!IfError End
      ;Get an array of choices
      ^!SetArray %ar%=^$GetDocMatchAll([^|}{]++)$
      ;Randomly choose element number
      ^!Set %n%=^$Calc(CEIL(RND(^%ar0%)))$
      ;Replace selection with the chosen alternative
      ^!InsertText ^%ar^%n%%
      ;Look for another set from the very top
      ^!Goto Random

      Naturally, a tiny sample without many alternatives is bound to produce some repeated results. I tested on a set of ten copies of this:

      The {quick|fast{ and furious|er}|speedy} brown fox jumped over the {lazy|bone idle} dog.
    • 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.