PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Nov 22, 2017 8:04 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: Sun Nov 27, 2005 2:15 am 
Offline
Forum Contributor

Joined: Tue Jun 24, 2003 7:33 pm
Posts: 181
Wonderful tutorial. Espcially to regex noobs like me. This got my form validation working. Good job.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 27, 2005 2:46 am 
Offline
DevNet Resident
User avatar

Joined: Wed Sep 25, 2002 7:47 pm
Posts: 1708
greatest tutorial on regex on the net imo.

great job.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 2:53 pm 
Offline
The Ninja Space Mod
User avatar

Joined: Fri Aug 05, 2005 1:53 pm
Posts: 6424
Location: Paradise, CA
great tutorial! my only question...
Quote:
One last thing before we build our first regex. Regex needs to be delimited if using Perl style regular expressions (preg_match()) which I strongly advise you do (Note: ereg_...() is not perl style).

To delimit a regex we start and end with the EXACT same character. The two standards are (but you can use most non-alphanumeric characters):
Code:

/pattern/
#pattern#

Why does it have to be delimited? What does that mean?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 3:26 pm 
Offline
Her Royal Site Adminness
User avatar

Joined: Tue Apr 23, 2002 2:21 am
Posts: 5371
Location: Essex, UK
The Ninja Space Goat wrote:
Why does it have to be delimited? What does that mean?

Delimiters mark the beginning and end of a pattern - if you use pattern modifiers then they would be added after the ending delimiter. The delimiter you'll probably see most often is a forward slash (/).
Quote:
To delimit a regex we start and end with the EXACT same character. The two standards are (but you can use most non-alphanumeric characters):
Code:

/pattern/
#pattern#

Mac


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 6:24 pm 
Offline
Forum Contributor
User avatar

Joined: Sun Jul 09, 2006 1:00 am
Posts: 121
Location: la plata - argentina
infolock wrote:
greatest tutorial on regex on the net imo.

great job.



Absolutely true. I ask myself why I didn't find it before.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 06, 2006 6:16 pm 
Offline
Forum Contributor
User avatar

Joined: Thu Jan 08, 2004 9:28 am
Posts: 404
Location: Helsinki
Actually, this is best Regexp tutorial i've come across with!

I made this in notime, and just 15 minutes ago it seemed impossible!

Syntax: [ Download ] [ Hide ]
 
        # Cut out linefeeds and whitespace around them!
        $value = preg_replace("#\\s{0,}\\r\\n\\s{0,}#", "", $value);
 


I think it was not mentioned, that PHP itself, needs to escape few characters as well, like the Regexp escape character \ or ", with the php escape char: (also) \

So in other words, if your regexp is
Syntax: [ Download ] [ Hide ]
 
#\s{0,}\r\n\s{0,}#
 


in php it needs to be
Syntax: [ Download ] [ Hide ]
 
#\\s{0,}\\r\\n\\s{0,}#
 


Last edited by Shendemiar on Fri Apr 25, 2008 12:35 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 5:38 am 
Offline
Breakbeat Nuttzer
User avatar

Joined: Wed Mar 24, 2004 8:57 am
Posts: 13098
Location: Melbourne, Australia
Shendemiar wrote:
I think it was not mentioned, that PHP itself, needs to escape few characters as well, like the Regexp escape character \ or ", with the php escape char: (also) \


Well spotted ~Shendemiar :) That's very true. The same is true in JavaScript when creating a regexp object by using the syntax var re = new RegExp();. JavaScript is a little more friendly however since you don't need to use a string to make a pattern, you can do it literally:

Syntax: [ Download ] [ Hide ]
var re = /patterns?/; //No quotes needed so only one \ needed to escape


Perl is also friendly in this sense too:

Syntax: [ Download ] [ Hide ]
if ($string =~ /sun(?!shine)/i)
{
    print "$string contains the word "sun" but not the word "sunshine"";
}


PHP however always requires the use of a string.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 8:10 am 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
That's why I use single quotes for my regex pattern strings.. almost all strings really.


Top
 Profile  
 
 Post subject: It still works
PostPosted: Thu Mar 08, 2007 4:34 am 
Offline
Forum Newbie

Joined: Wed Feb 21, 2007 9:40 pm
Posts: 1
Great tutorial ... Really helps. Your'e all experts.. :D


Top
 Profile  
 
 Post subject: Excelent tutorial here
PostPosted: Tue Aug 21, 2007 1:30 pm 
Offline
Forum Regular
User avatar

Joined: Sun Jul 01, 2007 7:11 am
Posts: 870
This is an excellent tutorial.

[url]
http://www.webcheatsheet.com/php/regula ... ssions.php
[/url]


Top
 Profile  
 
PostPosted: Sun Sep 02, 2007 11:04 pm 
Offline
Forum Newbie

Joined: Tue Jun 05, 2007 7:55 am
Posts: 6
yacahuma wrote:
This is an excellent tutorial.

[url]
http://www.webcheatsheet.com/php/regula ... ssions.php
[/url]


yeah, it is.

Other links:
http://www.phpbuilder.com/columns/dario19990616.php3

http://www.vinuthomas.com/News/article/sid=416.html


Top
 Profile  
 
PostPosted: Wed Sep 26, 2007 1:35 pm 
Offline
Forum Contributor
User avatar

Joined: Sun Oct 22, 2006 1:47 am
Posts: 274
Location: Belgium
d11wtq wrote:
Syntax: [ Download ] [ Hide ]
Character         Matching

. (dot)           ANY single character at all

Syntax: [ Download ] [ Hide ]
Modifier         Effect

s                Ignore whitespace


Note that the above is not quite true.

The dot metacharacter does match any single character except for newlines.

I don't know exactly what you mean by 's modifier ignores whitespace'? Anyway, the s modifier just changes the meaning of the dot metacharacter which will then match newlines as well. Agree?


Top
 Profile  
 
PostPosted: Thu Jan 17, 2008 3:56 am 
Offline
Forum Newbie

Joined: Thu Jan 17, 2008 3:53 am
Posts: 1
Great content.


Top
 Profile  
 
PostPosted: Thu Jan 22, 2009 8:47 am 
Offline
Forum Contributor
User avatar

Joined: Tue Mar 30, 2004 5:24 am
Posts: 433
Location: London, UK
This is a great tutorial. I refer to it all the time.

However I think I've found one slight inaccuracy regarding the s modifier which could be updated.

I use the regex coach utility to check out what's happening, and its explanation of the s modifier is "Treat string as single line"
When I was building a regex recently, the tutorial had me wondering why it wasn't working when I used the m modifier as I didn't think the s one was for me. As soon as I switched to the s modifier after looking at that bit on the regex coach, it worked straight away.

Cheers, B


Top
 Profile  
 
PostPosted: Thu Jan 22, 2009 9:02 am 
Offline
Forum Regular
User avatar

Joined: Wed Aug 27, 2008 3:36 am
Posts: 958
Location: Sweden/Sthlm
Very nice tutorial!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group