I am searching for a way to replace and update a string value in MySQL starting or ending with a percentage.
I would like values like the following:
'15 % flour'
' 15 % beef'
'15% pork'
' 15 % rice'
'eggplant 15 %'
'banana 15 % '
'turkey 15%'
'chicken 15% '
In all these examples I would like to end out with only the ingredient. Ex: flour or beef
I found out that this will remove the percentage if in the starting of the line. REGEXP_REPLACE(ingredient_name, '^([0-9]|100)+(\%)+', '') But not if there is space between the number and the percentage symbol.
This was my best try, but I found out it wasn't compatible with Mysql regexp_replace.
\d+((' '|\s|\b)\%(' '|\s|$))
' *[0-9]+ *% *'or'[[:space:]]*[0-9]+[[:space:]]*%[[:space:]]*'. What is the MySQL version?[[:blank:]]*[[:digit:]]+[[:blank:]]*%[[:blank:]]*^[^a-zA-Z]+|[^a-zA-Z]+$or^[^[:alpha:]]+|[^[:alpha:]]+$with empty string to see if this regex is supported in your mysql version. What's your mysql version though?[[:space:]]*[0-9]+[[:space:]]*%[[:space:]]*,[[:blank:]]*[[:digit:]]+[[:blank:]]*%[[:blank:]]*and^[^a-zA-Z]+|[^a-zA-Z]+$seems to work. Whats the difference?^[^a-zA-Z]+|[^a-zA-Z]+$< This one removed national special characters in my ingredients. Therefore[[:space:]]*[0-9]+[[:space:]]*%[[:space:]]*seems to be the best solution.