I have a MYSQL database that needs some data removed from a field.
My current data is like this..
gttp://www.somesite.com?ref=1234567
gttp//notquitealink.com/ref.php?r=myreferral
I am trying to remove the gttp://www.somesite.com?ref= to leave only the last part after the =
so I want the data to look like this
1234567
myreferral
I found this code from a previous question. MySQL Regex Search and replace
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 ;
I ran it and it created a function that I could query on.
When I run this query....
UPDATE `tb_te_builder_user` SET tebu_refID = regex_replace('gttp(.*)=', '',tebu_refID);
I get 0 rows affected. (Query took 10.9480 sec)
But when I try to do a select
SELECT * FROM `tb_te_builder_user` WHERE tebu_refID REGEXP 'gttp(.*)='
I get well over 7,000 records returned.
I am not quite sure what to make of it... I think I am missing something very simple here.
I was also looking at this solution https://github.com/mysqludf/lib_mysqludf_preg#readme but I don't have rights to use the make command on my server. So I am left with trying to figure out what I am doing incorrectly.
Any help is appreciated.
 
     
    