grep string between strings

Posted by in Lagom

echo "beforestring-THIS IS THE STRING I WANT-afterstring" | \
grep -o -P '(?<=beforestring-).*(?=-afterstring)'