Friday, 3 February 2017

regex mysql | regex mysql query | mysql regex function

regex mysql | regex mysql query | mysql regex function


  • if you want to get the only text and numbers from varchar type field.
  • first you have to create on one function in you database.
  • than you fired query for using regexreplace();

Note :- 

this function have three argument.
Syntax :- regexreplace(regex,text ,replace text);
  1. your regex. 
  2. your text which you perform regex.
  3. your replace text.

Output :- 

----------------------------------------------------------------------------------
| input                              |   output                         |
----------------------------------------------------------------------------------
| Located (please select) |   Located please select  |
----------------------------------------------------------------------------------



Function :-


DELIMITER $$
 CREATE FUNCTION `regexreplace`(pattern VARCHAR(500),plaintext VARCHAR(500),replaceing VARCHAR(100))
RETURNS VARCHAR(500)
 DETERMINISTIC
 BEGIN
  DECLARE repl VARCHAR(500);
  DECLARE ch VARCHAR(1);
  DECLARE i INT;
  SET i = 1;
  SET repl = '';
  IF plaintext REGEXP pattern THEN
   loop_label: LOOP
    IF i>CHAR_LENGTH(plaintext) THEN
     LEAVE loop_label; 
    END IF;
    SET ch = SUBSTRING(plaintext,i,1);
    IF NOT ch REGEXP pattern THEN
     SET repl = CONCAT(repl,ch);

   ELSE
     SET repl = CONCAT(repl,replaceing);
    END IF;
    SET i=i+1;
   END LOOP;
  ELSE
   SET repl = plaintext;
  END IF;
  RETURN repl;
 END$$
 DELIMITER ;

Query :-


SELECT description as 'Input',
        regexreplace([^A-Za-z0-9 ]',description ,'') as 'Output'
 FROM your table_name
 where description REGEXP '[^A-Za-z0-9 ]';

16 comments:

  1. Thanks for appreciation, I recognize you and your friend list for upcoming post.

    ReplyDelete
  2. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    Devops Training in Chennai

    Devops Training in Bangalore

    Devops Training in pune

    ReplyDelete
  3. We are a group of volunteers and starting a new initiative in a community. Your blog provided us valuable information to work on.You have done a marvellous job!
    python training in OMR
    python training in Bangalore
    python training in rajajinagar

    ReplyDelete
  4. Really great post, I simply unearthed your site and needed to say that I have truly appreciated perusing your blog entries. I want to say thanks for great sharing.
    AWS Training in chennai
    AWS Training in bangalore

    ReplyDelete
  5. I was recommended this web site by means of my cousin. I am now not certain whether this post is written through him as nobody else recognise such precise about my difficulty. You're amazing! Thank you!
    Blueprism training in marathahalli

    Blueprism training in btm

    Blueprism online training

    ReplyDelete
  6. Awesome..You have clearly explained …Its very useful for me to know about new things..Keep on blogging..
    Blueprism training in tambaram

    Blueprism training in annanagar

    Blueprism training in velachery

    ReplyDelete
  7. Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us
    Data Science training in rajaji nagar | Data Science with Python training in chenni
    Data Science training in electronic city | Data Science training in USA
    Data science training in pune | Data science training in kalyan nagar



    ReplyDelete
  8. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    java training in jayanagar | java training in electronic city

    java training in chennai | java training in USA

    ReplyDelete
  9. This is such a good post. One of the best posts that I\'ve read in my whole life. I am so happy that you chose this day to give me this. Please, continue to give me such valuable posts. Cheers!

    angularjs Training in chennai
    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    ReplyDelete
  10. Hello I am so delighted I found your blog, I really found you by mistake, while I was looking on Yahoo for something else, anyways I am here now and would just like to say thanks for a tremendous post. Please do keep up the great work.

    Microsoft Azure online training
    Selenium online training
    Java online training
    Java Script online training
    Share Point online training


    ReplyDelete
  11. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

    ReplyDelete
  12. It's a wonderful post and very helpful, thanks for all this information about Java. You are including better information regarding this topic in an effective way.Thank you so much for your sharing...

    Android Training in Chennai

    Android Online Training in Chennai

    Android Training in Bangalore

    Android Training in Hyderabad

    Android Training in Coimbatore

    Android Training

    Android Online Training



    ReplyDelete