Skip to content

Instantly share code, notes, and snippets.

@PandaEox

PandaEox/loop.sh

Created Jun 18, 2014
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@nothingasis nothingasis commented Nov 11, 2020

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

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