musse1
musse1

Reputation: 389

Bash regular expression: print all matches from string

I have a $content variable which is a long string that contains the word "title" multiple times. How do I match title and print all of the matches in Bash regex?

[[ $content =~ title ]] && echo ${BASH_REMATCH}

This only prints the first match.

Upvotes: 0

Views: 900

Answers (1)

user.friendly
user.friendly

Reputation: 2258

Can you give us the value of $content and also your desired output? It sounds like you need to do something like:

echo ${BASH_REMATCH[*]}

Upvotes: 1

Related Questions