Pages

Your Ad Here

This Blog is not to read or go through

because, I have never been such a mess


Search the blog instead

Showing posts with label Bookmarks. Show all posts
Showing posts with label Bookmarks. Show all posts

Monday, January 2, 2012

Bookmark: Regex Replace for MySQL

Reference -
 http://techras.wordpress.com/2011/06/02/regex-replace-for-mysql/

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 ;
Note:
If you are using MySQL version 5.0.1 or higher, make sure you set the NO_BACKSLASH_ESCAPES mode ON, before you use the above function to replace any characters which are escaped with back slash “\”, ie: \A,\B,etc… See how to set the NO_BACKSLASH_ESCAPES mode here
Example on how to use this function
mysql> select regex_replace('[^a-zA-Z0-9\-]','','2my test3_text-to. check \\ my- sql (regular) ,expressions ._,');
Happy Coding!! :)

Wednesday, March 10, 2010

Tuesday, March 2, 2010

Programming Contest Questions

My Bookmarks for Programming Contest Questions

ACSL.org
http://acsl.org/acsl/00-01/
http://acsl.org/acsl

HP Code Wars Sample Problems
http://www.hpcodewars.org/index.php?page=samples

IPSC Questions Archives
http://ipsc.ksp.sk/old.php

List of all Programming Contests as defined in Open Directory
http://www.dmoz.org/Computers/Programming/Contests/

The International Obfuscated C Code Contest
http://www.ioccc.org/

ACM Programming Contest
http://homepages.ecs.vuw.ac.nz/~david/acm/

Waterloo Programming Contests
http://plg1.cs.uwaterloo.ca/~acm00/
Your Ad Here