Re: Parsing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 23-2-2015 7:18, Jigar Dhulla wrote:
Hi,

(.*?) - Any character


(\s*?) - Multiline spaces and tabs


First (Ron, Jigar), PLEASE don't top-post. The mailinglist rules state that you should BOTTOM POST instead. Try to keep to the rules on the php mailinglists; always.

Secondly, the above two regexp rules are slightly bloated. What they actually mean is:
( = start new catchable pattern
. = any character
* = 0 or more of the previous pattern
? = 0 or 1 of the previous pattern
) = end catchable pattern
\s = any whitespace character

So, what does (.*?) mean? Well, simply said "any character, occuring 0 or more times" occuring 0 or 1 times. But since the any character pattern already occurs 0 or more times, the pattern as a whole will either be matched (1 time) or not (0 times). Making the ? metacharacter useless. Now if it were (.+?) then it would state "one or more of any character, with the entire pattern optional. So in practice, the following patterns are equal in what they represent: (.*?), (.*), (.+?)

The same thing goes for \s*?

You can read up on Regular Expressions on http://www.php.net/manual/en/regexp.introduction.php

- Tul

---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux