Mahmudul Hassan Mahmudul Hassan - 4 months ago 14
MySQL Question

I want to get string inside the third bracket []

I have a string like

"Email Request processed successfully Emails:[xyz.abc@qubee.com.bd][HostName
=WSRC-AFFILIATE-1, Host Address = 192.168.103.105]"


How can i get
"xyz.abc@qubee.com.bd"
in mysql

Answer

If the pattern is same you can do something as

mysql> select 
 substring_index(
     substring_index('"Email Request processed successfully Emails:[xyz.abc@qubee.com.bd][HostName = WSRC-AFFILIATE-1, Host Address = 192.168.103.105]"',
    'Emails:[',-1
     ),
']',1) as s ;


+----------------------+
| s                    |
+----------------------+
| xyz.abc@qubee.com.bd |
+----------------------+