zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@sunsite.dk>
Subject: Re: Expanding when matching
Date: Sat, 24 Apr 2004 04:14:14 +0000	[thread overview]
Message-ID: <1040424041414.ZM17671@candle.brasslantern.com> (raw)
In-Reply-To: <20040423211540.GA1821@DervishD>

On Apr 23, 11:15pm, DervishD wrote:
}
}     $ print ${testvar/#This*%/Replaced}
}     This is my test var
} 
}     The example doesn't make much sense, but it illustrates what I
} mean. What I'm doing wrong? What am I not understanding?

I know Wayne has already answered, but:

The # and % tokens in ${var/pat/rep} are not analogous to regex ^ and $.
Rather, they're analogous to ${var#pat} and ${var%pat}.  Does that help?

For the analogs of ^ and $, you need (#s) and (#e) [and extendedglob].

    $ print ${testvar/(#s)This*var(#e)/Replaced}

} replace some numbers in one text that should be consecutive but are
} not, and they are interspersed with arbitrary text. What I know about
} them is that they are alone in a line, so they match certain regex,

    setopt extendedglob
    c=0; while read line; do print ${${line#<->(#e)}:-$[++c]}; done

(Replacing <-> with your pattern.)


  parent reply	other threads:[~2004-04-24  4:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-23 21:15 DervishD
2004-04-23 22:05 ` Wayne Davison
2004-04-24  7:48   ` DervishD
2004-04-24  4:14 ` Bart Schaefer [this message]
2004-04-24  7:57   ` DervishD

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=1040424041414.ZM17671@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@sunsite.dk \
    /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).