help-bash
[Top][All Lists]
Advanced

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

Re: Extracting parts fof a string


From: Andy Chu
Subject: Re: Extracting parts fof a string
Date: Wed, 10 Nov 2021 13:01:38 -0500

On Wed, Nov 10, 2021 at 12:24 PM fatiparty--- via <help-bash@gnu.org> wrote:
>
>
> I have the following string "sel" composed of "Record: Name".  I want to get 
> "Name"
> on the right hand side of colon ":", removing the starting space.

This question is vague but to extract strings, the most general way in
bash is to use =~ .  Follow this template

regex='foo(.*)bar'  # extended RE syntax, put this in a string to
avoid quoting issues
if [[ $mystr =~ $regex ]]; then
  extracted=${BASH_REMATCH[1]}  # the first group.  0 is the whole match
fi

(not tested)



reply via email to

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