#!/bin/bash

# clicker-rematch.sh
# demonstrate a clicker answer from Week 10 Lecture 2,
#     regarding the BASH_REMATCH array
#
# expects: one command line argument, which will be compared
#     to a regular expression
#
# by: Sharon Tuttle
# last modified: 2022-10-26

line=$1
echo "pre-if: $line"

echo
echo "using RE: moo(.+)moo(.+)moo"
echo

if [[ "$line" =~ moo(.+)moo(.+)moo ]]
then
    echo "<${BASH_REMATCH[0]}>"
    echo "<${BASH_REMATCH[1]}>"
    echo "<${BASH_REMATCH[2]}>"
    echo "<${#BASH_REMATCH[*]}>"
fi