Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: backreferences



On 10/15/2015 04:16 PM, Bart Schaefer wrote:

     [[ "$sstring" = (#b)([^i]#inside)(*) ]]
Very good, I tried a few things and missed the one that works. But I'm finding out that it's dangerous w.o. the test, since 'match' will remain silently unchanged if the
comparison fails.
... or it might mean that
you're trying to not-match multiple characters in the tested string in
a certain order.
Yes.

In the latter case you want ^(string), or more often
(^(string)), but you also must setopt EXTENDED_GLOB.
Sorry for the ambiguity. Clarity in the mind of the sender and clarity in the mind of the receiver are not the same thing. I mean that the match should fail not on meeting one character (or selection of characters), but it should fail on meeting
a specific sequence of characters:

   test ()
   {

   sstring="abcdeedcbaabcde"
   if [[ "$sstring" = (#b)([(^(edcba))]*)(edcba)(*) ]];

   then
          echo "you have a match"
   else
        match=
   fi

   echo "one   $match[1]"
   echo "two   $match[2]"
   echo "three $match[3]"
   }


    one   abcde
    two   edcba
    three abcde


I tried to learn how to do that with sed and never did get it figured out.
zsh can give us just about most of what we want anyway.  Pretty cool.

Thanks.



Messages sorted by: Reverse Date, Date, Thread, Author