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

Re: Help with Regex Clip Code to find the following pattern....

Expand Messages
  • diodeom
    ... Here s a possible take: ;Locate solo nested brace with its preceding and following stuff ... ^!Find (?
    Message 1 of 9 , Oct 10, 2010
    • 0 Attachment
      "Paul" <xboa721@...> wrote:
      >
      > Useful test text snippet:The quick|fast|slow} {brown|spott{ed|y} pink|grey} fox {{jumped|hopped} over the {lazy|bone idle} dog|swam around the lake}.
      >
      > NOTE: the first curly bracket that *should* appear before the quick is removed so the test code works on the second nested bracket.
      >
      > The result should be programmatically resolved to:
      > The {quick|fast|slow} {brown|spotted pink|spotty pink|grey} fox {{jumped|hopped} over the {lazy|bone idle} dog|swam around the lake}.
      >

      Here's a possible take:

      ;Locate solo nested brace with its preceding and following stuff
      :Brace
      ^!Find "(?<={|\|)([\w\40]*+){([\w\40|]++)}((?1))(?=\||})" WRS
      ^!IfError End
      ^!SetArray %brace%=^$GetReSubStrings$
      ;Get alternatives (at ^%brace2%)
      ^!SetArray %alt%=^$StrReplace(|;";";^%brace2%;0;0)$
      ^!Set %i%=0
      :Alt
      ^!Inc %i%
      ^!If ^%i%>^%alt0% Repl
      ;Edit the replacement string
      ^!Append %repl%=^%brace1%^%alt^%i%%^%brace3%|
      ^!Goto Alt
      :Repl
      ;Paste fixed alternatives and look for another case
      ^!Set %repl%=^$StrDeleteRight(^%repl%;1)$
      ^!InsertText ^%repl%
      ^!Set %repl%=
      ^!Goto Brace
    • Paul
      Now that looks more like familiar procedural code. Thankyou, will be back on this soon. Paul
      Message 2 of 9 , Oct 11, 2010
      • 0 Attachment
        Now that looks more like familiar procedural code. Thankyou, will be back on this soon.
        Paul

        > Here's a possible take:
        >
        > ;Locate solo nested brace with its preceding and following stuff
        > :Brace
        > ^!Find "(?<={|\|)([\w\40]*+){([\w\40|]++)}((?1))(?=\||})" WRS
        > ^!IfError End
        > ^!SetArray %brace%=^$GetReSubStrings$
        > ;Get alternatives (at ^%brace2%)
        > ^!SetArray %alt%=^$StrReplace(|;";";^%brace2%;0;0)$
        > ^!Set %i%=0
        > :Alt
        > ^!Inc %i%
        > ^!If ^%i%>^%alt0% Repl
        > ;Edit the replacement string
        > ^!Append %repl%=^%brace1%^%alt^%i%%^%brace3%|
        > ^!Goto Alt
        > :Repl
        > ;Paste fixed alternatives and look for another case
        > ^!Set %repl%=^$StrDeleteRight(^%repl%;1)$
        > ^!InsertText ^%repl%
        > ^!Set %repl%=
        > ^!Goto Brace
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.