The preference for mother's voice over a stranger's voice has been show in utero by Kisilevsky et al. (2003) by measuring the fetus' heart rate. It increased in response to mother's voice and decreased in response to a stranger's voice compared to baseline. Kisilevsky and Hains (2011) followed up the earlier study, and determined that the onset of recognition occurred at 32–34 weeks GA. Thus, at least for vocal stimuli, there is definitely some recognition from the infants. My only issue with these studies is that the mothers could hear the stimuli, thus there could be interaction from a hormonal response of the mother to her own voice and the fetus picking up on that instead of the actual auditory input.
An even more liberal reading of "recognition" as defined by the OP is possible. If we follow in the footsteps of Maturana and Varela then we should talk about the brain/mind responding not to external stimuli but to its own internal sensory world. In that case, we can consider adaptation even before sensory organs are fully developed or functional. In that case the fetus starts to adapt to senses-to-be before they develop.
Penn & Shatz (1999) showed that the connections from the eye to the visual cortex form before the retina is developed enough to respond to light. At this time the retinal ganglion cells spontaneously generate highly correlated bursts of action potentials similar to the sort of data they will generate once they actual start sensing. The preliminary bursts allow the human fetus to start developing its visual cortex before it even has functional retina. Thus, the brain of the fetus starts to learn and recognize patterns before it even has proper external sensory input.