help-bash
[Top][All Lists]
Advanced

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

referring to the matched string in pattern replacement


From: Peng Yu
Subject: referring to the matched string in pattern replacement
Date: Wed, 14 Apr 2021 08:58:16 -0500

I want to replace a character matching a character class regex by a
pair of brackets enclosing the matched strings.

For example, if the regex is [A-Z], and the string is aXz, the output is a(X)z.

I don't see this syntax is capable of doing this. I could spell out
the characters in the character class, but that is tedious.

${parameter/pattern/string}

Is there any other smart way to achieve this in bash efficiently
without calling external programs?

-- 
Regards,
Peng



reply via email to

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