WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Newbie Notes #7 - Ridiculous regex
Categories : PHP, Beginner Guides, Regexps Click here to Update Your Picture
Simon Booth
Date : Apr 21st 2004
Grade : 1 of 5 (graded 3 times)
Viewed : 4536
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Simon Booth
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

NewbieNotes is a little series of tips for people who are new to PHP to give them a few handy tips that the more experienced of us use often

No matter what you want to do with PHP one day you're going to need to use regex (regular expressions)

There's lots and lots available to read but how come when you put it in your first regex it don't work?

The most obvious thing is that you didn't escape one of the proliferation of back-slashes in a typical regex srting

Usage Example
looking for a whitespace characher in regex is denoted by \w - your PHP needs to write that as \\w - i.e. every \ in the real regex string needs to be doubled up


OK - it still don't work - experiment without PHP in the way!

Pop off to http://www.weitz.de/regex-coach/ and download Regex Coach. This excellent little program will show you exacly what your regex string is doing

Now, as long as you remember to escape your string properly you can experiment to you're heart's content and learn by experimentation

You'll still need the regex reference, this will just make it more understandable



a PHP Function to Get only the filename (remove the extension) using regular expressions.
Categories : PHP, Regexps, Beginner Guides
Validating a URL with preg_match
Categories : PHP, Regexps, Beginner Guides, Data Validation
Username Validation function
Categories : PHP, Beginner Guides, Regexps
Cut your MySQL Connections to 1 line of code
Categories : PHP, Beginner Guides, Databases, MySQL
Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
Basic Authentication with sessions
Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions
Introduction to Language Files
Categories : PHP, Filesystem, Beginner Guides
News management class
Categories : PHP, PHP Classes, Beginner Guides
A flat file counter
Categories : PHP, Cookies, Filesystem, Beginner Guides
A very simple PHP single password cookie based login without usernames.
Categories : PHP, Cookies, Security, Beginner Guides
PHP Email image generator - hide your email from bots - using the GD Library
Categories : PHP, Graphics, GD image library, Beginner Guides
Simple way to replace a variable value in a .conf (.ini) file using a webbrowser - the first stage of a complete universal configuration editor
Categories : PHP, Regexps, Code Editors, Filesystem
ereg -- Regular expression match
Categories : PHP, PHP Functions, Regexps
Different Call User Functions
Categories : PHP, Functions, Beginner Guides
Creating a Language File
Categories : PHP, Beginner Guides, Filesystem
 Shiraz Esat wrote : 1086
The most obvious thing is that you didn`t escape one of the proliferation of back-slashes in a typical regex srting 

e.g. looking for a whitespace characher in regex is denoted by \w - your PHP needs to write that as \\w - i.e. every \ in the real regex string needs to be doubled up 

Regarding having to double up \s: this only applies if you`re double quoting (") as opposed to single quoting (`) (when single quoting, though, you`ll need \` if you wish a ` to be a part of your regex).
It`s important to know how PHP treats strings, and the different between double-quoting, single-quoting and heredocs.
 
 Jose Santos wrote :1104
Thanks!
The Regex Coach it`s very good !!
The regular expressions in php is very useful.
See http://www.phpbuilder.com/manual/pcre.pattern.syntax.php.
It`s a very good website to describe regular expressions