WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 : 7108
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  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



PHP based HTML rabbing Tools
Categories : PHP, HTML and PHP, Tag Extractors, Regexps, Beginner Guides
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
I need a trim function/regexp that will trim all " " from the ends of a string.
Categories : Regexps, PHP, Strings
Cut your MySQL Connections to 1 line of code
Categories : PHP, Beginner Guides, Databases, MySQL
How to preset a text string in a textarea input field
Categories : HTML, HTML and PHP, PHP, Beginner Guides
Reverse a given number
Categories : PHP, Beginner Guides, Algorithms, Math.
Local Time clock and Server time usign PHP and JavaScript
Categories : PHP, Java Script, Date Time, Beginner Guides
Basic Authentication with sessions
Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions
Newbie Notes #4 - Trapping dumb MySQL query errors
Categories : PHP, Databases, MySQL, Debugging, Beginner Guides
How to build a search query for any N number of words in a search string
Categories : PHP, Regexps, Search Engines, Search
PHP Domain Availability Checker
Categories : PHP, Complete Programs, Regexps, HTTP, Sockets
PHP based Contact email form with multiple recipients, text file based, supports departments.
Categories : PHP, Email, Beginner Guides, Filesystem
Easy alert box pop-up function
Categories : PHP, Java Script, Beginner Guides
 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