Potresti usare le regular expression ma da una ricerca rapida ho letto che con le funzioni out of the box non č possibile estrarre un pattern da una stringa.
Ci sono delle librerie esterne che aggiungono questa funzionalitą, tipo quella della risposta di questa domanda su stackoverflow:
http://stackoverflow.com/questions/5...n-regexp-query