Using PCREs
(Page 1 of 5 )
In this tutorial, Sam shows you how to use Regular Expressions.
By : Sam Fullman
There are a bunch of good elementary tutorials out there on Regular Expressions. Just do a search at google.com.
However, what I am about to share encapsulates many of the frustrations I encountered in developing expressions that would work every time, and that always captured any variant in the string I was searching.
So if you're banging your head against the monitor even after you have read other articles, this is the one to read. You can think of this as the advanced class. If you're looking to get file strings off the web and do editing or analysis, you need to know this stuff. You may not always need to be this complex when you develop regex'es, but if you'll study the concepts, you can be assured you've learned something, and have the confidence you'll find what you're looking for (if it's there).
Before you begin this tutorial, you need to go to the following page I've created for testing Regular Expressions (you'll probably want to bookmark this page).http://samuelfullman.com/team/php/tools/regular_expression_tester_p.php
Next, you'll want to know the actual php code you can use for any of the outlined regular expressions (regexes) through this tutorial:
<?php $subject = "some string strung strong of text"; $findMatches = preg_match_all('/str.ng/',$subject,$matches); if($findMatches){ for($i=0;$i<count($matches[0]);$i++){ echo $matches[0][$i] . "<BR>"; } } ?> |
Next: Section 1 >>
More Miscellaneous Articles
More By Codewalkers