CJB
CJB

Reputation: 13

extracting strings from mysql field

total slow moment day, i need to extract different areas based on what language is selected from a field in a mysql database

ex:

<!--:en-->Overview<!--:--><!--:es-->Overview<!--:--><!--:fr-->Présentation<!--:--><!--:ar-->نظرة عامة<!--:-->

so if my language is french for example, i want the part between <!--:fr--> and <!--:-->

any ideas?

Upvotes: 1

Views: 384

Answers (2)

Karolis
Karolis

Reputation: 9562

Strings processing is not the strongest part of MySQL. But here is one idea:

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(column_name, '<!--:fr-->', -1), '<!--:-->', 1) FROM table_name

Upvotes: 3

HackerGil
HackerGil

Reputation: 1722

The easier way would be using a substring. You can find the index for the language on the string first. After that, find the index of the end marker () and extract what's in the middle, which is the value you want.

A more elaborated way would be using regular expressions. The implementation depends on the language you are coding on.

Upvotes: 0

Related Questions