grep
uses POSIX style regular expression which are always greedy. If your grep supports the -P
flag, you can use it to enable perl style regex which do support non-greedy matches:
grep -oP "javascript:add2BasketProd.*?jpg"
The GNU grep
, which is used on linux, supports -P
. The Mac OSX grep
does not.