Probably this:
#!/usr/bin/env bash
array=()
string="/packages/frontend/react-app/src/index.ts"
[[ $string =~ packages/([^/]+/){2} ]] && array+=("${BASH_REMATCH[0]}")
Explanation:
[^/]+
match any non-empty string that does not contain a /
.
CLICK HERE to find out more related problems solutions.