Skip to content
Advertisement

From string, extract a word starting with a keyword (SQL or any other methods?)

Let’s say I have a string of random characters, and I want to extract only the string that starts after a specific keyword (including the keyword). How could I do so using MySQL or MariaDB? …………..

String example:

axdsSSFddlwie ====> SSFddlwie

aldfklafnlanaSSFiiie ====> SSFiiie

iiiSSFnnnn ====> SSFnnnn

Thanks for the help!

Advertisement

Answer

Using the base string functions we can try:

SELECT SUBSTRING(col, INSTR('SSF', col))
FROM yourTable;

If you are using MySQL 8+, then REGEXP_SUBSTR is another option:

SELECT REGEXP_SUBSTR(col, 'SSF.*')
FROM yourTable;
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement