24 lines
370 B
Bash
24 lines
370 B
Bash
|
|
#!/bin/bash
|
||
|
|
|
||
|
|
#
|
||
|
|
# Three word regular expression
|
||
|
|
#
|
||
|
|
re='^([a-zA-Z]+) +([a-zA-Z]+) +([a-zA-Z]+) *\.?'
|
||
|
|
|
||
|
|
#
|
||
|
|
# A sentence is expected as the only argument
|
||
|
|
#
|
||
|
|
if [[ $# -ne 1 ]]; then
|
||
|
|
echo "Usage: $0 sentence"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "Sentence: $1"
|
||
|
|
if [[ $1 =~ $re ]]; then
|
||
|
|
echo "Matched"
|
||
|
|
for i in {0..3}; do
|
||
|
|
printf '%2d %s\n' $i "${BASH_REMATCH[$i]}"
|
||
|
|
done
|
||
|
|
fi
|
||
|
|
|