Search
 
SCRIPT & CODE EXAMPLE
 

SQL

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
Comment

mysql regexp replace

WITH t AS (SELECT 'aaa <b>bbb</b> ccc' AS teststring FROM dual)

SELECT
  teststring,
  regexp_replace(teststring, '<.+>') AS reg1,
  regexp_replace(teststring, '<.*>') AS reg2,
  regexp_replace(teststring, '<.*?>') AS reg3
FROM t


TESTSTRING             REG1        REG2          REG3
aaa <b>bbb</b> ccc     aaa ccc     aaa ccc       aaa bbb ccc
Comment

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 ;
Comment

PREVIOUS NEXT
Code Example
Sql :: sql get month and year from date 
Sql :: oracle pl/sql package 
Sql :: php get closest location by latitude longitude 
Sql :: sql view index 
Sql :: how to create a table based on another table in mysql 
Sql :: json_remove mysql 
Sql :: sql where not like in list 
Sql :: sql alter column 
Sql :: sql vs nosql or mysql vs mongodb 
Sql :: finish transaction sql 
Sql :: oracle alter table add column 
Sql :: decimal() mysql 
Sql :: sql server datetime 
Sql :: set column width in sqlplus 
Sql :: add column postgresql 
Sql :: multiple left join mysql 
Sql :: sql server select record with max id 
Sql :: microsoft sql server python connection 
Sql :: how to get table id sequence postgres 
Sql :: enum in sql server 
Sql :: oracle sql developer 
Sql :: How do I UPDATE from a SELECT in SQL Server? 
Sql :: mysqldump devilbox 
Sql :: oracle list user locked 
Sql :: Write a PL/SQL to print even numbers upto 100. 
Sql :: how to get second highest salary in each department in sql 
Sql :: oracle disk group space 
Sql :: triggers in mysql example 
Sql :: index postgres 
Sql :: compound trigger oracle 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =