[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: referring to the matched string in pattern replacement
From: |
Leonid Isaev (ifax) |
Subject: |
Re: referring to the matched string in pattern replacement |
Date: |
Wed, 14 Apr 2021 18:44:39 +0000 |
On Wed, Apr 14, 2021 at 01:35:14PM -0500, Peng Yu wrote:
> > I think you have to use a regex:
> >
> > s=aXz
> > [[ $s =~ (.*)([A-Z])(.*) ]]
> > echo "${BASH_REMATCH[1]}(${BASH_REMATCH[2]})${BASH_REMATCH[3]}"
> > a(X)z
>
> OK. When there are multiple matches, it seems to be quite cumbersome.
Is this discussion [1] relevant here?
[1] https://stackoverflow.com/questions/41143014/bash-regex-ungreedy-match
--
Leonid Isaev