fork download
  1. #!/bin/bash
  2. s='Some.text.1234.text
  3. Some.text.1234.i10u20.text
  4. Some.text.1234.I01U02.text
  5. Some.text.1234.i83U23.text'
  6. extractrx='(.+)\.([0-9]+)\.[^.]+$'
  7. for f in $s; do
  8. if [[ "${f^^}" =~ I[0-9]{2}U[0-9]{2} ]]; then
  9. echo "$f is invalid";
  10. else
  11. if [[ "$f" =~ $extractrx ]]; then
  12. echo "Result: '${BASH_REMATCH[1]}' and '${BASH_REMATCH[2]}'"
  13. else
  14. echo "$f is valid"
  15. fi;
  16. fi;
  17. done;
Success #stdin #stdout 0s 4720KB
stdin
Standard input is empty
stdout
Result: 'Some.text' and '1234'
Some.text.1234.i10u20.text is invalid
Some.text.1234.I01U02.text is invalid
Some.text.1234.i83U23.text is invalid