fork download
  1. #!/bin/bash
  2.  
  3. function handle_value {
  4. local one=$1
  5. local two=$2
  6.  
  7. echo "i found ${one}-${two}"
  8. }
  9.  
  10. function match_all {
  11. local current=$1
  12. local regex=$2
  13. local handler=$3
  14.  
  15. while [[ ${current} =~ ${regex} ]]; do
  16. "${handler}" "${BASH_REMATCH[@]:1}"
  17.  
  18. # trim off the portion already matched
  19. current="${current#*${BASH_REMATCH[0]}}"
  20. done
  21. }
  22.  
  23. match_all \
  24. "DO-BATCH BATCH-DO" \
  25. '([[:alpha:]]+)-([[:alpha:]]+)' \
  26. 'handle_value'
Success #stdin #stdout 0.01s 5624KB
stdin
Standard input is empty
stdout
i found DO-BATCH
i found BATCH-DO