I need to delete words before a set of words in a field.

eg delete the words before the word price in that field.

I already have a query to replace a certain word but cant see how adapt it to do what I require
update TABLE set field = replace(field,'price','');

can somebody help please?
Thanks in advance

Member Avatar

You'd probably need to do a regexp replacement, but MySQL doesn't have one. You could try this: https://github.com/hholzgra/mysql-udf-regexp

However you can use LOCATE() or POSITION() to find the position of a word and then you can trim the field using SUBSTRING():

Something like this...

UPDATE table1 SET field1 = IF(LOCATE('$TEXT',field1) > 0, SUBSTRING($field1, LOCATE('$TEXT', field1)), field1)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.