1

given those strings in a mysql column...

All of the above  (-2/2)
All of the above  (0/3)
Once or twice  (1/3)

is it possible to do a replace in order to delete the brackets and their content?

thanks

7
  • Do you store exactly those strings, or is the (n/n) variable? Commented Feb 14, 2014 at 15:50
  • yes, unfortunately is variable... Commented Feb 14, 2014 at 15:51
  • 1
    But otherwise, the text is either All of the above or Once or twice? And you want the end result to strip off the (n/n) entirely, resulting in All of the above or Once or twice? Commented Feb 14, 2014 at 15:52
  • the text is variable and the content inside the brackets is variable as well I need to remove all brackets and content Commented Feb 14, 2014 at 15:56
  • Still not clear - I thought it was but your last comment confuses me a little. Please edit your question post a sample of existing rows, and a corresponding sample of what the expected output looks like. MySQL does not have native regular expression replacements, unfortunately, but this may be doable with regular string operations. Commented Feb 14, 2014 at 16:00

1 Answer 1

1

here you go:

create table rep(
sometext text
);
insert into rep(sometext) values('All of the above  (-2/2)'),
('All of the above  (0/3)'),
('Once or twice  (1/3)');
update rep set sometext = replace(sometext,substring(sometext,locate('(',sometext)),'');

I used replace, then I found the substring of the text using locate, to send it as second arg to replace.

References: Locate , substring , replace

FIDDLE.

Sign up to request clarification or add additional context in comments.

5 Comments

Probably wrap that in RTRIM() as well.
Thanks for your reply. I thins this is not exactly what I need, because if I have this row "All of the above (some text) bla bla (1/2)" I should get "All of the above (some text) bla bla" anyway thanks for your help
@user3174311 - which row do you mean?!
basically, I need to replace "/\s(\d\/\d)/" with an empty string
ok, i don't see the problem here?! the only thing you are missing is the space which as Michael mentioned you can wrap the update with RTRIM to solve it!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.