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

Re: [NTB] Regular expression help

Expand Messages
  • Art Kocsis
    ... That s an easy one that even I can answer: use a non-greedy quantifier: +? or {1,}? (.+(?= s+?v s)) I have been training myself to use the horizontal
    Message 1 of 1 , Aug 12 4:37 PM
    • 0 Attachment
      At 8/12/2012 11:42 AM, you wrote:
      >Hi need help on a reg exp.
      >
      >Suppose we have team names like:
      >
      >Buffalo Bills v Miami Dolphins
      >
      >I can use a regular expression to get Team 1 like:
      >
      >(.+(?=\sv\s))
      >
      >and capture it into a variable.
      >
      >But is what regular expression would I use if there were more than 1 space
      >between the v:
      >
      >Buffalo Bills v Miami Dolphins
      >
      >Anyone help ?

      That's an easy one that even I can answer: use a non-greedy quantifier:
      "+?" or "{1,}?"

      (.+(?=\s+?v\s))

      I have been training myself to use the horizontal white space metachar "\h"
      instead
      of the anything white space "\s" as "\s" includes line termination such as
      CRLF which
      I may not want. So:

      ^!Jump Line_Start
      ^!Find "^.+(?=\h+?v\h)" IRST
      ^!IfError ^!Info Team 1 not found
      ^!Set %T1%=^$GetSelection$
      ^!Find "^.+\h+?v\h+?\K.+$" IRST
      ^!IfError ^!Info Team 2 not found
      ^!Set %T2%=^$GetSelection$
      ^!Info T1, T2 =^%nl% ^%T1%^%nl% ^%T2%

      ;Alternately,
      ^!SetDelimiter ;
      ^!Jump Line_Start
      ^!Find "^(.+)\h+?v\h+?(.+?)$" IRST
      ^!SetArray %T%=^$GetReSubStrings$
      ^!Info T(sgl) =^%nl% ^%T%

      ;Or, to capture them all in one shot:
      ; Note: this should have worked but it does not. There appears to be a
      bug in $GetDocReplaceAll()$

      ^!SetArray %T%=^$GetDocReplaceAll("^(.+)\h+?v\h+?(.+?)$";"$1;$2")$
      ; where ^%T^%i%% is team 1 for ^%i% odd and team 2 for ^%i% even
      ^!Info T(all) =^%nl% ^%T%

      Namaste', Art

      BTW, this discussion really belongs in the clips forum. Go there for
      further posts.
    Your message has been successfully submitted and would be delivered to recipients shortly.