Understanding RegExps

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
visionmaster
Forum Contributor
Posts: 139
Joined: Wed Jul 14, 2004 4:06 am

Understanding RegExps

Post by visionmaster »

Hello,

I just made the experience that RegExps are WORN (write once, read never). I actually got help in this forum for the following RegExps, but unfortunately can not "read" them anymore. Can anybody give me a detailed, step by step description of the RegExps, so I really can understand the pattern?

preg_match_all('#^descr:\s*(.*?)\s*$#m', $array[3], $matches);

preg_match('#^\s*([^\s]+?)\s+(.*?)\s*$#s', $array[3], $matches);


Thanks a lot,
visionmaster
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

1. find all lines that start with the string 'descr:' followed by any number of spaces, remember all characters outside of trailing spaces until the end of the line.

2. remember the first word (excluding leading spaces), remember the following until the end of the string (excluding leading and trailing spaces)
visionmaster
Forum Contributor
Posts: 139
Joined: Wed Jul 14, 2004 4:06 am

Post by visionmaster »

O.k., I think I got it. The only thing that still confuses me is (.*?)

Thanks
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

visionmaster wrote:O.k., I think I got it. The only thing that still confuses me is (.*?)

Thanks
I think that (.*?) is what the script forwards, ie, what you are looking for.
That's probably all I know about RegExps :P
Post Reply