zsh-users
 help / color / mirror / code / Atom feed
* Remove multiple characters after match
@ 2023-12-19  7:34 Jörg Sommer
  2023-12-20 22:28 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Jörg Sommer @ 2023-12-19  7:34 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 649 bytes --]

Hi,

I want to remove space at the begin and end of a match, and I thought
this should work, but it doesn't:

```
% x=( 'abc ,,*.i,, 123' 'abc ,, *.i,, 123' 'abc ,,    *.i,, 123' 'abc ,,*.i ,, 123' 'abc ,,*.i   ,, 123' 'abc ,,   *.i   ,, 123' )
% print -l -- -${(*)^${(*)x#*,, #}%% #,,*}-
-*.i-
- *.i-
-    *.i-
-*.i-
-*.i-
-   *.i-
```

How can I remove the spaces after the left delimiter?


Regards Jörg


-- 
Manchmal denke ich, das sicherste Indiz dafür, daß anderswo im Universum
intelligentes Leben existiert, ist, daß niemand versucht hat, mit uns
Kontakt aufzunehmen.                           (Calvin und Hobbes)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 269 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Remove multiple characters after match
  2023-12-19  7:34 Remove multiple characters after match Jörg Sommer
@ 2023-12-20 22:28 ` Bart Schaefer
  2023-12-21  7:22   ` Jörg Sommer
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2023-12-20 22:28 UTC (permalink / raw)
  To: Jörg Sommer; +Cc: zsh-users

On Mon, Dec 18, 2023 at 11:34 PM Jörg Sommer <joerg@jo-so.de> wrote:
>
> How can I remove the spaces after the left delimiter?

You're trying to get the shortest match for (*) and the longest match
for ( #), which doesn't work.  I think your best bet is to first
remove all the spaces around delimiters:

${(*)x// #,, #/,,}

And then leave space matching out of the # and % constructions:

% print -l -- -${(*)^${(*)${(*)x// #,, #/,,}#*,,}%,,*}-
-*.i-
-*.i-
-*.i-
-*.i-
-*.i-
-*.i-

You didn't actually say what output you wanted but I think that's it?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Remove multiple characters after match
  2023-12-20 22:28 ` Bart Schaefer
@ 2023-12-21  7:22   ` Jörg Sommer
  0 siblings, 0 replies; 3+ messages in thread
From: Jörg Sommer @ 2023-12-21  7:22 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1160 bytes --]

Bart Schaefer schrieb am Mi 20. Dez, 14:28 (-0800):
> On Mon, Dec 18, 2023 at 11:34 PM Jörg Sommer <joerg@jo-so.de> wrote:
> >
> > How can I remove the spaces after the left delimiter?
> 
> You're trying to get the shortest match for (*) and the longest match
> for ( #), which doesn't work.

Ahh. That makes sense. Thanks for this explanation.

> % print -l -- -${(*)^${(*)${(*)x// #,, #/,,}#*,,}%,,*}-
> -*.i-
> -*.i-
> -*.i-
> -*.i-
> -*.i-
> -*.i-
> 
> You didn't actually say what output you wanted but I think that's it?

Yes, that's it. In the end I used this code to make entering for loops
easier, e.g. `git -C ,, ~/git/*(/),, grep …`. Zsh is really cool!

```
accept-line()
{
    case "$BUFFER" in
      *,,?*,,*)
        BUFFER="for i in ${${${BUFFER#*,,}## #}%% #,,*}; do ${BUFFER/,,?*,,/\$i}; done"
        ;;
    esac
    zle .accept-line
}
zle -N accept-line
```

Thanks and regards,

Jörg

-- 
> Ich kenn mich mit OpenBSD kaum aus, was sind denn da so die
> Vorteile gegenueber Linux und iptables?
Der Fuchsschwanzeffekt ist größer. :->
Message-ID: <slrnb11064.54g.hschlen@humbert.ddns.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 269 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-21  7:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-19  7:34 Remove multiple characters after match Jörg Sommer
2023-12-20 22:28 ` Bart Schaefer
2023-12-21  7:22   ` Jörg Sommer

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).