SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: RegExp

  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,157
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    RegExp

    Hi,

    Can someone enlighten my mind on how to use Regexp?please i want to know how to use this.
    Thank you.

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,617
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    The first few hits on google offer plenty of info:

    http://en.wikipedia.org/wiki/Regular_expression

    http://www.regular-expressions.info/

    Do you have any specific questions?
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,197
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If you are specifically referring to the RegExp() function that JavaScript offers to run regular expressions you need not have to learn anything new as all it is for us as developers is a shortcut to creating expressions that can contain dynamically generated expressions, see the below examples for a normal expression using // and and another using the RegExp() function.

    Code JavaScript:
    var myString = 'Does this string contain Chris?';
    alert(myString.match(/Chris/i));

    Code JavaScript:
    var myString = 'Does this string contain Chris?',
        search   = prompt('Please enter a name to search for', '');
     
    if (match) {
        alert(myString.match(new RegExp(search), 'i'));
    }

  4. #4
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,157
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by chris.upjohn View Post
    If you are specifically referring to the RegExp() function that JavaScript offers to run regular expressions you need not have to learn anything new as all it is for us as developers is a shortcut to creating expressions that can contain dynamically generated expressions, see the below examples for a normal expression using // and and another using the RegExp() function.

    Code JavaScript:
    var myString = 'Does this string contain Chris?';
    alert(myString.match(/Chris/i));

    Code JavaScript:
    var myString = 'Does this string contain Chris?',
        search   = prompt('Please enter a name to search for', '');
     
    if (match) {
        alert(myString.match(new RegExp(search), 'i'));
    }

    Hi, thank you for this example,is the RegExp can be use to search a word in database?because i am making program like search box using HttpRequest and in my query in database i use WHERE name like "%searchword%".and i want to change this to use the RegExp..is this possible?Thank you in advance and i am hoping for your positive response


Bookmarks

Posting Permissions

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