non-greedy grep

Standard grep does not accept the ? modifier that would normally make it non-greedy.

But you can try the -P option that - if enabled in your distro - will make it accept Perl style regexes:

grep -oP -m1 "(https)[^'\"]+?.mp3" mp3.txt

If that does not work, you could for your specific example include the right parenthesis in the range so it wouldn't look beyond the parenthesis:

egrep -o -m1 "(https)[^'\")]+?.mp3" mp3.txt

egrep does not support non-greedy matching. Using perl mode -P will help you:

grep -o -m1 -P  'https.*?mp3' example.txt

Tags:

Grep