data:
locator: urn:asset:a1e2d1df-a741-6547-93e2-e84692c8e981
locator: urn:bbc:cps:asset:27510321
script:
#!/bin/bash
while read l
do
if [[ $l =~ [(\w*:\s\w*:\w*:)(\w*-.*)] ]]; then
for i in "${BASH_REMATCH[@]}"
do
echo "Index: $i"
done
echo "${BASH_REMATCH[2]}"
fi
done < data.txt
I think Crystal's matches because surrounding the whole regex in
[ ]
makes Bash treat the whole regex as a single character class, and because that class contains characters that could match anything it does match everything - so you're right, it is matching all the individual letters, but is capturing none of them.Looking at mine again, of course I had forgotten that
.+
matches spaces, so it matches all characters up until the final:
, then captures everything up to the end.