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

Re: [NTB] Stripping text up to a given character

Expand Messages
  • ebbtidalflats
    ... Thanks for clearing that up. One question remains. Does this carry into a nested parentesis? Would (one)(?:two(four)){3}(three) bring the same result as in
    Message 1 of 5 , Jun 7, 2009
    • 0 Attachment
      --- In ntb-clips@yahoogroups.com, "Sheri" <silvermoonwoman@...> wrote:
      >
      > I'm not sure I understand your question, but any time you use ?: for a group, it causes that group to be non-capturing. You must then skip that set of parentheses for counting groups to retrieve by number. So if you have:
      >
      > (one)(?:two){3}(three)
      >
      > where matched, "one" would be in $1 and "three" would be in $2.


      Thanks for clearing that up. One question remains. Does this carry into a nested parentesis?


      Would (one)(?:two(four)){3}(three) bring the same result as in your above example?


      TIA


      Eb
    • Sheri
      ... You would need ?: in the (four) group to avoid capturing it. Because it is inside a repeating group, it is useless when captured imo. (four) would be in $2
      Message 2 of 5 , Jun 7, 2009
      • 0 Attachment
        --- In ntb-clips@yahoogroups.com, "ebbtidalflats" <ebbtidalflats@...> wrote:
        >
        > --- In ntb-clips@yahoogroups.com, "Sheri" <silvermoonwoman@> wrote:
        > >
        > > I'm not sure I understand your question, but any time you use ?: for a group, it causes that group to be non-capturing. You must then skip that set of parentheses for counting groups to retrieve by number. So if you have:
        > >
        > > (one)(?:two){3}(three)
        > >
        > > where matched, "one" would be in $1 and "three" would be in $2.
        >
        >
        > Thanks for clearing that up. One question remains. Does this carry into a nested parentesis?
        >
        >
        > Would (one)(?:two(four)){3}(three) bring the same result as in your above example?
        >
        >
        > TIA
        >
        >
        > Eb
        >

        You would need ?: in the (four) group to avoid capturing it. Because it is inside a repeating group, it is useless when captured imo. (four) would be in $2 and would contain the last "four" in the third occurrence of twofour in:

        onetwofourtwofourtwofourthree

        You can test it by running
        ^!Replace "(one)(?:two(four)){3}(three)" >> "*$2*" RSA2

        against document text:
        onetwofourtwofourtwofourthree
        onetwofourtwofourtwofourthree
        onetwofourtwofourtwofourthree

        Regards,
        Sheri
      Your message has been successfully submitted and would be delivered to recipients shortly.