Count Regex Matches

Count how many times a regex pattern matches in a string.

Code

General
echo "$str" | grep -oE "$pattern" | wc -l | tr -d ' '

Parameters

String to search

Pattern to count

Server

More Bash Snippets