zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: backreferences
Date: Fri, 16 Oct 2015 09:37:56 -0700	[thread overview]
Message-ID: <562127E4.2050804@eastlink.ca> (raw)
In-Reply-To: <151016053555.ZM31602@torch.brasslantern.com>

On 10/16/2015 05:35 AM, Bart Schaefer wrote:
> } when nested and even when 'doing something else'?
>
> Yes.

Ok, good to know.  I've only been using backreferences since two days 
ago and up till now it's seemed that you had to add parentheses to 
create the reference and existing parentheses only had their existing 
syntax.  I suppose this means that when you do have existing parentheses 
you'll get a 'match' whether you want one or not but so what, just  
ignore it.  Yup, that's best.
> ... but the part about not needing the
> middle * is wrong, because (^edcba) matches xxxxedcbaxxxx just fine, and
> I assume you don't want that.

    test2 ()
    {
    match=
    sstring="abcdeedcbaabcde"
    # Bart doesn't like:
    #if [[ "$sstring" = (#b)([(^(edcba))]*)(edcba)(*) ]];
    # Bart likes:
    if [[ "$sstring" = (#b)(^edcba)(edcba)(*) ]];

    then
       echo "\nIt's a poyfect match\n"
    fi

    echo "one   $match[1]"
    echo "two   $match[2]"
    echo "three $match[3]"
    echo "four  $match[4]"
    echo "five  $match[5]"
    }

    It's a poyfect match

    one   abcde
    two   edcba
    three abcde
    four
    five

... match[1]  seems to agree with your previous interpretation, no?


> This needs to be (#b)(^edcba*)(edcba)(*)

That produces identical output as well, so what's the diff? Probably one 
of those things that blows up in your face one day ...
> } 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:
> } [....]*
>
> No, now you're confusing grep-style regular expressions with zsh patterns.

... which is what I meant to say.
>      EGREP	ZSH
>      .		?
>      .*		* or ?#
>      .+		?##
>      .?		(?|)
>      [xyz]	[xyz]
>      [xyz]*	[xyz]#
>
> There's a lot more but those are the most important bits.

A table like that is worth tattooing onto one's arm.  Seriously once a 
fella has learned a bit of regex it becomes burnt into the brain, and 
it's an act of deliberation to use the other syntax.  It sorta makes it 
worse that they are similar :(  Is a complete table available somewhere?
> } ... so you can see where I'd go astray there.  Ok, so
> } ^(edcba)
> } is individual character matches and
> } (^edcba)
> } is  anything up to "edcba"
>
> No.  [^edcba] is individual character matches and (^edcba) is anything
> other than the literal string edcba,

Ok, got it.  A mortal's guide to this stuff would sure be useful. All 
the docs tend to dive right in to the deep end and immediately start 
explaining all the possible obscure permutations when KSH_GLOB is set 
and it's not leap year but it IS a Friday.  Such control!  But we start 
with the basics.
> including longer strings that have
> edcba as a substring.  Negated patterns are really tricky.

Na.


  reply	other threads:[~2015-10-16 16:38 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       ` backreferences Ray Andrews
2015-10-16 12:35         ` backreferences Bart Schaefer
2015-10-16 16:37           ` Ray Andrews [this message]
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=562127E4.2050804@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).