help-bash
[Top][All Lists]
Advanced

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

Re: referring to the matched string in pattern replacement


From: Peng Yu
Subject: Re: referring to the matched string in pattern replacement
Date: Wed, 14 Apr 2021 13:35:14 -0500

> 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.
For the case of a character class without too many characters, it is
probably better just go with replacing each character within the
class?

-- 
Regards,
Peng



reply via email to

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