Dhiraj M
Dhiraj M

Reputation: 23

Extracting Text between sub strings in MySQL

I have a text like the below

[:de]

Die BB2 ist eine erlesene türkische Gulet in klassischer Holzbauweise, die alle Annehmlichkeiten und die Eleganz einer exklusiven Yacht, die durch die hohe Qualität der vorzüglichen Holzverarbeitung und das anspruchsvolle Design untermalt wird. Auf 37 m Länge bietet Sie Ihnen 15 moderne, klimatisierte, große Kabinen mit Duschkabine / WC. Salon und Deck sind ausgesprochen großzügig angelegt und mit edlem Mobiliar ausgestattet. Die professionelle und erfahrene Crew ist auf das Beste damit vertraut für die Sicherheit und Zufriedenheit der Gäste zu sorgen und Ihnen einen Rundumservice zu bieten.

[:en]

At 37 x 10 m the BB2 is designed to portray elegant style with a relaxing atmosphere. She is one of the most perfect examples of the Turkish wooden gulets with all amenities of an exclusive yacht. 15 modern, air-conditioned cabins with shower and toilet are on offer for the guests on board. The salon and deck are spaciously designed and equipped for your comfort. The professional and experienced crew is more than familiar in making sure the guests feel safe and comfortable and offer a great service all around.

[:]

[:en] represents English text and [:de] represents German text

want output for a language in MySQL. What will be the query to extract text in German only?

Upvotes: 1

Views: 134

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270391

Assuming this is your data with the german always before the english, then:

select substring_index(substring_index(col, '[:de]', -1), '[:en]', 1)

If this is not the case, you can test for different possibilities:

select (case when col like '%[:de]%[%:en]%'
             then substring_index(substring_index(col, '[:de]', -1), '[:en]', 1)
             when col like '%[:de]%[%:]%'
             then substring_index(substring_index(col, '[:de]', -1), '[:]', 1)
             else substring_index(col, '[:de]', -1)
       end)

Upvotes: 1

Related Questions