zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: backreferences
Date: Thu, 15 Oct 2015 22:36:56 -0700	[thread overview]
Message-ID: <56208CF8.1070906@eastlink.ca> (raw)
In-Reply-To: <151015193032.ZM30783@torch.brasslantern.com>

On 10/15/2015 07:30 PM, Bart Schaefer wrote:
> On Oct 15,  6:16pm, Ray Andrews wrote:
> } Subject: Re: backreferences
> }
> }     if [[ "$sstring" = (#b)([(^(edcba))]*)(edcba)(*) ]];
>
> Umm, no.
But ... but ... it worked.  So it works for the wrong reason then you 
say.  Ok
the right answer for the wrong reason could do a great deal of damage so
thanks for rescuing me.

> [(^(edcba))] is still a character class (open paren, caret,
> e,d,c,b,a, close paren).  Just (^(edcba)) without the square brackets.
> And you have more parens then, so your $match[] indexes are wrong.
>
> 	if [[ "$sstring" = (#b)((^(edcba))*)(edcba)(*) ]]
>
> There are 5 sets of parens, and you care about $match[1], $match[4],
> and $match[5].  $match[2] is the prefix of $match[1] that was not
> consumed by the middle *, and $match[3] is an empty substring of
> $match[2] (because it was excluded from matching).  Count off the
> open parens left to right to see this.
At the moment I'm quite confounded.  So '(b#)' is looking at every set 
of '()' even
when nested and even when 'doing something else'? (That is to say even when
they are doing other syntax work?)  I may be doing something wrong but using
the above my output is:

one   abcde
two   edcba
three abcde
four
five


> In fact you don't even need the middle * because (^edcba) will eat
> an arbitrarily long string as long as it is not literally "edcba".
Well, that's the original question.

> So you can reduce this to
>
> 	if [[ "$sstring" = (#b)(^edcba)(edcba)(*) ]]
>
> and then you're back to only needing $match[1,3].
>
God knows.  But your simplified command works fine too, and I'll
take it on faith.  I've never seen any sort of 'any number of characters'
sort  of thing look other than:
[....]*
... so you can see where I'd go astray there.  Ok, so
^(edcba)
is individual character matches and
(^edcba)
is  anything up to "edcba" ... which is exactly what I wanted. Let's leave
my other effort to the devil--I don't even want to understand it.


  parent reply	other threads:[~2015-10-16  5:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-15 18:28 backreferences Ray Andrews
2015-10-15 23:16 ` backreferences Bart Schaefer
2015-10-16  1:16   ` backreferences Ray Andrews
2015-10-16  2:30     ` backreferences Bart Schaefer
2015-10-16  4:11       ` backreferences Mikael Magnusson
2015-10-16  4:27         ` backreferences Kurtis Rader
2015-10-16  5:42           ` backreferences Ray Andrews
2015-10-16  5:05         ` backreferences Bart Schaefer
2015-10-16  5:28           ` backreferences Bart Schaefer
2015-10-16  5:46             ` backreferences Ray Andrews
2015-10-16 11:14         ` backreferences Peter Stephenson
2015-10-16  5:36       ` Ray Andrews [this message]
2015-10-16 12:35         ` backreferences Bart Schaefer
2015-10-16 16:37           ` backreferences Ray Andrews
2015-10-17  3:33             ` backreferences Bart Schaefer
2015-10-17  5:16               ` backreferences Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56208CF8.1070906@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).