Skip to content

Instantly share code, notes, and snippets.

@PandaEox
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
Copy link

nothingasis commented Nov 11, 2020

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