ASP
  Home arrow ASP arrow Page 4 - The Complete Regular Expression Guide
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  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
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? 
ASP

The Complete Regular Expression Guide
By: Jan Borsodi
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 31
    2002-12-27

    Table of Contents:
  • The Complete Regular Expression Guide
  • Usage
  • Assertions
  • Wildcards
  • Conclusion

  • 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


    The Complete Regular Expression Guide - Wildcards


    (Page 4 of 5 )

    For people who have some knowledge of wildcards, I will give you a brief explanation of how to convert them to regular expressions. A typical wildcard looks like this:

    *.jpg

    ... and matches any text which end with .jpg. You can also specify brackets with characters, for example:

    *.[ch]pp

    ...matches any text which ends in .cpp or .hpp.

    Examples
    To really get to know regular expressions, I've left some commonly used expressions on this page. Study them, experiment with them and try to understand exactly what they accomplish.

    Email validity will only match email addresses which are valid, for instance user@host.com:

    [a-z0-9_-]+(\.[a-z0-9_-]+)*@[a-z0-9_-]+(\.[a-z0-9_-]+)+

    Email validity #2 matches email addresses with a name in front, for instance "Joe Doe":

    ("?[a-zA-Z]+"?[ \t]*)+\<[a-z0-9_-]+(\.[a-z0-9_-]+)*@[a-z0-9_-]+(\.[a-z0-9_-]+)+\>

    Protocol validity matches web based protocols such as htpp://, ftp:// or https://

    [a-z]+://

    C/C++ includes matches valid include statements in C/C++ files:

    ^#include[ \t]+[<"][^>"]+[">]

    C++ end of line comments

    //.+$

    Floating point numbers match simple floating point numbers such as 1.2 and 0.5:

    -?[0-9]+\.[0-9]+

    Hexadecimal numbers match C/C++ style hex numbers such as 0xcafebabe:

    0x[0-9a-fA-F]+

    Utilities
    There are several utilities that use regular expressions for data extraction, text validation, etc. I will leave you with brief descriptions of some of them.

    grep
    Grep searches named input files for lines containing a match to the given pattern. It can also be used to find files that contain a specific pattern, for instance:

    grep -E "cow|vache" * >/dev/null && echo "Found a cow"

    This utility is rather common on Linux distributions, but if you don't have it you can grab a version on the GNU page.

    A small tip is to enable extended regular expressions with the –E option. If you don't enable it, then a lot of the meta-characters explained earlier in this article won't work.

    sed
    Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream. This utility is rather common on Linux distributions, but if you don't have it you can grab a version on the GNU page.

    gawk
    Gawk is the GNU Project's implementation of the AWK programming language. It conforms to the definition of the language in the POSIX 1003.2 command Language and utilities standard. This is utility is rather common on Linux distributions, but if you don't have it you can grab a version on the GNU page.

    RegExplorer
    RegExplorer is a visual regular expression explorer. It allows for writing regular expressions and visually seeing matches, thus making regular expression much easier to write and maintain. You can grab a copy at the RegExplorer page.

    Visual RegExp
    This software will let you design your regexp’s by letting you type the expression and visualize its effect on a sample piece of text. You can grab a copy at the Visual RegExp page.

    Regexx
    Regexx is a complete regular expression solution for C++. It implements easy expression execution, global searching, replace with atom substitution, customized replaces, easy match and atom strings retrieving. Grab a copy at it's home page.

    More ASP Articles
    More By Jan Borsodi


     

    ASP ARTICLES

    - Central Scoreboard with Flash and ASP
    - Calorie Counter Using WAP and ASP
    - Creating PGP-Encrypted E-Mails Using ASP
    - Be My Guest in ASP
    - Session Replacement in ASP
    - Securing ASP Data Access Credentials Using t...
    - The Not So Ordinary Address Book
    - Adding and Displaying Data Easily via ASP an...
    - Sending Email From a Form in ASP
    - Adding Member Services in ASP
    - Removing Unconfirmed Members
    - Trapping HTTP 500.100 - Internal Server Error
    - So Many Rows, So Little Time! - Case Study
    - XDO: An XML Engine Class for Classic ASP
    - Credit Card Fraud Prevention Using ASP and C...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway