You need to change the quotes:
for i in {1..5}
do
echo "${2}.svg" | grep "rect'rect x=\042$i\042"x = '$'\042'$i$'\042' && do_something_if_${i}_is_found
done
\042 is the ASCII representation of double quotes.
Check man ascii
Or simply:
grep "rect x=\"$i\""