help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: trim both prefix and suffix without using intermediate variable


From: Peng Yu
Subject: Re: trim both prefix and suffix without using intermediate variable
Date: Sat, 21 Jan 2023 06:38:02 -0600

I’ve never thought about this clever way of using BASH_REMATCH. This is a
quite useful trick especially when one does not want to pollute the
variable space.

On Fri, Jan 20, 2023 at 9:14 PM Alan D. Salewski <salewski@att.net> wrote:

> On 2023-01-20 19:22:29, Peng Yu <pengyu.ut@gmail.com> spake thus:
> >
> https://stackoverflow.com/questions/40055221/is-there-a-way-to-remove-both-the-prefix-and-suffix-in-one-shot-in-bash-using
> >
> > I see that it says impossible to trim both a prefix and a suffix from
> > a string without using an intermediate variable. Is it so?
> >
> > --
> > Regards,
> > Peng
>
>
> $ BASH_REMATCH='startmiddleend'
> $ if [[ $BASH_REMATCH =~ ^start(.*)end$ ]]; then echo ${BASH_REMATCH[1]};
> fi
> middle
>
>
> --
> a l a n   d.   s a l e w s k i
> ads@salewski.email
> salewski@att.net
> https://github.com/salewski
>
> --
Regards,
Peng


reply via email to

[Prev in Thread] Current Thread [Next in Thread]