Created
June 18, 2014 10:42
-
-
Save PandaEox/5215e33dca9c14076eff to your computer and use it in GitHub Desktop.
Bash: Loop over regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just wanted to say that this came in handy. Thanks!