MySQL regex – Get text in one query

Assume we have a table like this in MySQL

tbl_test

-----------------------------------------------------
| ID | text                                         |
-----------------------------------------------------
| 1  | Lorem ipsum n Teacher: Mr. Brown n Age: 43 | 
| 2  | Dolor n Teacher: Mrs. Morgan n Age: 35     | 
-----------------------------------------------------

Is it possible to get the name of the teachers with one single SQL Query.
The expected result should be:

 Mr. Brown
 Mrs. Morgan

I thought of something like a regex SQL query. I have already tried it with LIKE but then I get the whole text and not only the teacher’s name.

SELECT text FROM tbl_test WHERE text LIKE '%Teacher%';

Output

Lorem ipsum n Teacher: Mr. Brown n Age: 43
Dolor n Teacher: Mrs. Morgan n Age: 35


Source: regex

Leave a Reply