Miscellaneous
  Home arrow Miscellaneous arrow Page 5 - Using PCREs
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
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? 
MISCELLANEOUS

Using PCREs
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-11-16

    Table of Contents:
  • Using PCREs
  • Section 1
  • Section 2
  • Section 3
  • Wrapping Things Up

  • 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


    Using PCREs - Wrapping Things Up


    (Page 5 of 5 )

    Here's the final version of the "catch-all" href regular expression:

    /<a(\s)+[^>]*href(\s)*=(\s)*('|")*[^"'>]+('|")*[^>]*(\s)*>(.|\s)*?<\/a(\s)*>/i

    Finally, there's one more thing I didn't tell you that has caused me grief as well, and that is escaping ' and \ characters.

    When you specify a regular expression, you're expressing a string, so of course you put it in either single or double quotes. I recommend you always use SINGLE quotes, because you only need to escape the single quote character itself. So my final href regex:

    /<a(\s)+[^>]*href(\s)*=(\s)*('|")*[^"'>]+('|")*[^>]*(\s)*>(.|\s)*?<\/a(\s)*>/i

    becomes this:

    '/<a(\s)+[^>]*href(\s)*=(\s)*(\'|")*[^"\'>]+(\'|")*[^>]*(\s)*>(.|\s)*?<\/a(\s)*>/i'

    even though the compiler is going to "see" the first string.

    Well, I had promised you that this was complex, but hopefully if you've taken some time and thought on this tutorial, you'll be less likely to be surprised when developing these expressions. Oh, and refer a friend to my regular expression tester!

    About the Author

    Sam Fullman is a web designer, database consultant and programmer. He is currently working on the RelateBase.com project, a new venture which will allow end users, IT people, and webmasters to set up fully relational databases. For more information go to www.relatebase.com or the parent website, www.compasspointmedia.com


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Thank you for this tut. I read over the section on regular expressions in the PHP...
       · There was I wondering how to get HTML tags out of a chunk of text (and wondering why...
     

    MISCELLANEOUS ARTICLES

    - Using PHP to Stream MP3 Files and Prevent Il...
    - 10 Must Have Firefox Improvements
    - All About OpenOffice 3.0
    - Shell Script Writing
    - Loops in the UNIX Shell
    - The Test in the UNIX Shell
    - Data Streams and the UNIX Shell
    - Control Mechanisms of the UNIX Shell
    - Variables Within the UNIX Shell
    - The Shell and UNIX
    - In Detail: UNIX File Systems
    - Rights Management in UNIX
    - UNIX File Systems
    - The Terminal in UNIX
    - Operating Systems and UNIX





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