dcsimg
www.webdeveloper.com
Results 1 to 8 of 8

Thread: replace function

  1. #1
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    51

    replace function

    Hey... I am newbie to Javascript. I wanted to replace the dot operator and some escape characters using regular expressions. Could anyone help me out in this?

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by Manasipradeep View Post
    Hey... I am newbie to Javascript. I wanted to replace the dot operator and some escape characters using regular expressions. Could anyone help me out in this?
    What for? can you detail your aim, please?

  3. #3
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    51
    it is to check for a valid domain name when booking a domain name in my site.

  4. #4
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    51

    Smile

    Quote Originally Posted by Manasipradeep View Post
    it is to check for a valid domain name when booking a domain name in my site.

    I have something like this in my code.

    function trim(str)
    {
    return str.replace(/^\s*|\s*$/g,"");
    }

    So I just wanted to know how this works..

  5. #5
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    So, you are talking about a string, in which case you probably mean the dot character, not the dot operator. Anyway, in JavaScript syntax the dot is not an operator...

    Give us an example of a string. How it looks before, and how do you want it to look like after the RegExp replacements.

  6. #6
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    51
    I am talking about strings with special characters

    Eg..

    /* Obtain, parse and clean the domain name from the textbox */
    function getDomainToLookupValue() {
    var domain = getDomainTextBox().value;
    var output = trim(domain).toLowerCase();

    output = output.replace(/https?\:\/\//, '');
    output = output.replace(/\/.*/, '');

    return output;
    }


    function trim(str)
    {
    return str.replace(/^\s*|\s*$/g,"");
    }

    So I just wanted to know how this works..

  7. #7
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Study the Regular Expressions in JavaScript:
    http://lawrence.ecorp.net/inet/samples/regexp-intro.php

  8. #8
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    51
    Thanks Kor. I will look into this... Thanks for sending the link.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles