In many (all?) unix shells, globs are expanded by the shell before being passed to the program.
'ls *.jpg'
is passed expanded to 'ls 1.jpg 2.jpg 3.jpg' BEFORE ls is run. This choice means that if a program wants to use another style of regular expression (ie: pcre), it must be enclosed in quotes on the shell, ie: "ls | grep -P '.*jpg'"