mysql regex replace
REGEXP_REPLACE(expression, pattern, replacement[, position[, occurrence[, match_type]]])
Example 1 - remove all "-" characters
SELECT REGEXP_REPLACE( fieldname, '-', '' ) AS newfieldname FROM tablename
mysql regex replace
REGEXP_REPLACE(expression, pattern, replacement[, position[, occurrence[, match_type]]])
Example 1 - remove all "-" characters
SELECT REGEXP_REPLACE( fieldname, '-', '' ) AS newfieldname FROM tablename
mysql replace regex
DELIMITER $$
CREATE FUNCTION `regex_replace`(pattern VARCHAR(1000),replacement VARCHAR(1000),original VARCHAR(1000))
RETURNS VARCHAR(1000)
DETERMINISTIC
BEGIN
DECLARE temp VARCHAR(1000);
DECLARE ch VARCHAR(1);
DECLARE i INT;
SET i = 1;
SET temp = '';
IF original REGEXP pattern THEN
loop_label: LOOP
IF i>CHAR_LENGTH(original) THEN
LEAVE loop_label;
END IF;
SET ch = SUBSTRING(original,i,1);
IF NOT ch REGEXP pattern THEN
SET temp = CONCAT(temp,ch);
ELSE
SET temp = CONCAT(temp,replacement);
END IF;
SET i=i+1;
END LOOP;
ELSE
SET temp = original;
END IF;
RETURN temp;
END$$
DELIMITER ;
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us