Skip to content

Instantly share code, notes, and snippets.

@PandaEox
Created June 18, 2014 10:42
Show Gist options
  • Save PandaEox/5215e33dca9c14076eff to your computer and use it in GitHub Desktop.
Save PandaEox/5215e33dca9c14076eff to your computer and use it in GitHub Desktop.
Bash: Loop over regex
#!/bin/bash
# Thx to: http://mykospark.net/2014/01/iterating-through-regular-expression-matches-with-bash/
COMMENT=$1
REGEX_ISSUE_ID="([A-Z]+-[0-9]+|[0-9]{3,})"
while [[ ${COMMENT} =~ (${REGEX_ISSUE_ID}) ]]; do
echo "${BASH_REMATCH[1]}"
COMMENT=${COMMENT##*${BASH_REMATCH[1]}}
done
@nothingasis
Copy link

Just wanted to say that this came in handy. Thanks!

@n33pm
Copy link

n33pm commented May 26, 2021

🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment