0

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!

Community
  • 1
  • 1
Jae Jang
  • 15
  • 4
  • This could help you https://stackoverflow.com/questions/31853466/extract-string-from-a-text-after-a-keyword-in-sql – Ciprian Jun 02 '20 at 10:24

2 Answers2

1

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;
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

You can use substring_index():

select concat('SSF', substring_index(col, 'SSF', -1))
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786