string - Select Concat Substring and Replace in MySQL -


i have .sql file needs characters removed , text left. inside " ". example of text field in column

a:1:{i:0;s:9:"test word here";}

a:1:{i:0;s:11:"test words here too";}

so want words. test word here. , test words here too. left in text field.

i went this.

  update `questions`   set answer = replace(replace(replace(replace(answer, 'a:1', ''), 's:4', ''), 'i:0', ''), ',', '') 

but realized s:4 has s:5, s:16 etc. wouldn't work. next attempt use concat , remove amount of characters starting a:1. able working select. not able replace work. below can see working select.

select concat('tt',           substring(`answer`, -locate('a:1', `answer`)+15)    ) `questions`; 

here attempt @ getting replace work it. i'm stuck. i'm open suggestions, in case i'm going in complete wrong direction here anyways.

select concat(replace('tt',           substring(`answer`, -locate('a:1', `answer`)+15))    ) `questions`; 

how substring_index()?

update `questions`     set answer = substring_index(substring_index(answer, '"', 2), '"', -1) 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -