JavaScript
  Home arrow JavaScript arrow Page 2 - Case and Negation in JavaScript Regular Ex...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Case and Negation in JavaScript Regular Expressions
By: Chrysanthus Forcha
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-07-22

    Table of Contents:
  • Case and Negation in JavaScript Regular Expressions
  • Abbreviations for Common Character Classes
  • Beginning and Ending a String
  • Matching Repetitions
  • Matching the Whole String

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Case and Negation in JavaScript Regular Expressions - Abbreviations for Common Character Classes


    (Page 2 of 5 )

    d

    d stands for any digit, and it abbreviates [0-9]. The following code produces a match:

     

    /IDdid/.test("ID5id is an ID")

     

    Negated d

    D is negated d. It represents any character that is not a digit; that is, [^0-9].

     

    s

    trnf are white space characters. ' ' or simply ' ' is produced when you press the spacebar of your keyboard. t is produced when you press the tab key on your keyboard. r is the carriage return character. n is the new line character and f is the form feed character. 

    s is the abbreviation for any white space character. That is s is equivalent to [ trnf].  

    The following code produces a match:

     

    var alertMsg = "The first line.rnThe second line."

     

    /n/.test(alertMsg)

     

    The following code also produces a match:

     

    /s/.test(alertMsg)

     

    Negated s

    S

    S is negated s. It represents any character that is not a white space, that is [^s]. 

    S, [^s] and [^ trnf] are equivalent.  

    The negation symbol negates the class within the square brackets.

     

    w

    This is a word character. It represents any alphanumeric character, including the underscore. w and [0-9a-zA-Z_] are equivalent.

     

    Negated w

    W is negated w. It represents any non-word character. W and [^w] are equivalent.

     

    The Period '.'

    The period '.' matches any character except n. For example, /.s/ matches 'is' in the available string "An apple is on the tree." /.s/ represents two characters, that is any character (except n) followed by 's'.

    The dswDSW and dot abbreviations can be used both inside and outside of character classes. Here are some in use: 

    /dd:dd:dd/ : matches an hh:mm:ss time format, e.g 05:45:30.

    /[ds]/ : matches any digit or any white space character.

    /wWw/ : matches a word char, followed by a non-word char, followed by a word char.

    /..rt/ : matches any two chars, followed by 'rt'

    /end./ : matches 'end.'

    /end[.]/ : also matches 'end.' 

    More JavaScript Articles
    More By Chrysanthus Forcha


     

    JAVASCRIPT ARTICLES

    - Using jQuery to Preload Images with CSS and ...
    - Using Client-Side Scripting to Preload Image...
    - Removing Non-Semantic Markup when Preloading...
    - Using the Display CSS Property to Preload Im...
    - Preloading Images with CSS and JavaScript
    - Scaling and Moving Web Page Elements with th...
    - Fading, Hiding and Sliding HTML Elements wit...
    - Toggling CSS Properties with the GX JavaScri...
    - Cancel, Queue and Pause Animations with the ...
    - Producing Elastic Effects with the GX JavaSc...
    - Moving Divs Diagonally with the GX JavaScrip...
    - Moving Elements Vertically and Horizontally ...
    - Making Bouncing Effects in Parallel with the...
    - Creating Bouncing Effects with the GX JavaSc...
    - Manipulating Background Colors with the GX J...







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek