iLTC Home
Bookmark iLTC!
iLTC Google Boards

Google Groups
Receive The Code in Email!



Categories

Perl
  • Perl Tutorials Beginners

    Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

    HTML
  • HTML Tutorials



  • Pass the Javascript, please...
    123,704

    iLoveTheCode.com
    Javascript > Javascript Tutorials How To Easy > Match with a Regular Expression, REGEX, in Javascript

    Match with a Regular Expression, REGEX, in Javascript



    You have a variable named jiji that contains a sentence.

    var jiji="I see London.";

    You name your regular expression variable huhu and write a pattern for what you are looking for. (We aren't writing any regex patterns here so the code is legible. We'll just use the word "london", but this is where you put your regex. - example: \s for spaces \n for unix line returns, etc.)

    var huhu=/london/i;

    You test the variable jiji for the regex variable huhu

    if (huhu.test(jiji)) {
    document.write("Matches!");
    }
    else {
    document.write("Doesn't Match!");
    }


    NOTES:
    -The i at the end of huhu makes the match pattern case-insensitive. Remove the i to make match case-sensitive.
    -test() is a built-in Javascript method


    Copy and Paste Javascript Code:

    <script type=text/javascript>
    <!--
    var jiji="I see London.";

    var huhu=/london/i;

    if (huhu.test(jiji)) {
    document.write("Matches!");
    }
    else {
    document.write("Doesn't Match!");
    }
    -->
    </script>


    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    Previous Article: PRINT to Browser with document.write Command in Javascript
    Next Article: If, Else If, and Else in Javascript





    Creating Web SitesCreating Web Sites

    Matthew MacDonald

    New $19.77

    Dreamweaver CS3Dreamweaver CS3

    David McFarland

    New $29.69

    Head First HTML with CSS...Head First HTML with CSS & XHTML

    Eric Freeman, Elis...

    New $23.99

    CSSCSS

    Eric Meyer

    New $29.69

    Bulletproof Web DesignBulletproof Web Design

    Dan Cederholm

    New $23.99

    Learning Web DesignLearning Web Design

    Jennifer Niederst ...

    New $26.99

    CSSCSS

    David McFarland

    New $23.09

    HTML, XHTML, and CSS, Si...HTML, XHTML, and CSS, Sixth Edition ...

    Elizabeth Castro

    New $23.09

    HTMLHTML

    Gary B. Shelly, Th...

    New $84.55


    Of Interest:
  • What's in an Array, Index Numbers
  • Finding the Length (Index Numbers) of an Array in Perl
  • Matching at the Beginning and End 2
  • Substitute in Perl
  • Javascript Splice - Use Splice to Replace Items in an Array in Javascript
  • Increment a Variable in Javascript
  • Get Query String Using Javascript
  • Opening a REMOTE WINDOW in Javascript
  • Make a New Paragraph Using HTML
  • Make Strikethrough Text Using HTML
  • HTML Space
  • HTML Font Code

  • More Articles:
  • If, Elsif, and Else in Perl
  • Write a FOR LOOP in Perl
  • Finding the Length (Index Numbers) of an Array in Perl
  • Renaming a File with Perl's RENAME Function
  • onClick Javascript
  • Mimic Typing from a Textfield in a Textarea with Javascript
  • Write a For Loop in Javascript
  • Use onLoad to Call More than One Function with Javascript
  • Make Text Bold Using HTML
  • Make Strikethrough Text Using HTML
  • HTML Center
  • HTML Body Tag

  • Search iLTC w/ Google





    Recent Articles

  • Javascript Focus Form Field
  • Javascript Lowercase Text
  • Javascript Uppercase Text
  • Javascript Superscript Text
  • Javascript Subscript Text
  • Make Text Blink Using Javascript
  • Make a String into a Link in Javascript
  • Javascript Italics Text
  • Javascript Bold Text
  • Javascript Redirect
  • HTML Frames
  • HTML Color Chart
  • HTML Link
  • Javascript Status Bar








  • Perl Programming - Javascript Programming - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006 iLoveTheCode.com


    Contact Chris | About this Site


    420,465
    Counter by iLoveTheCode.com


    Last Modified: Thursday, 10-Jan-2008 23:14:55 EST