Re: [PHP-DB] how does this regular expression works

2011-07-14 Thread Richard Quadling
On 13 July 2011 13:42, who.cat  wrote:
> ]*>(.*?)



]*>(.*?)

Options: case insensitive; ^ and $ match at line breaks

Match the characters “” «[^>]*»
   Between zero and unlimited times, as many times as possible, giving
back as needed (greedy) «*»
Match the character “>” literally «>»
Match the regular expression below and capture its match into
backreference number 1 «(.*?)»
   Match any single character that is not a line break character «.*?»
  Between zero and unlimited times, as few times as possible,
expanding as needed (lazy) «*?»
Match the characters “” literally «»


Created with RegexBuddy
-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

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



Re: [PHP-DB] how does this regular expression works

2011-07-14 Thread Richard Quadling
On 13 July 2011 14:04, Shahriyar Imanov  wrote:
> \(?P.*?)\<\/head\>



(?P.*?)

Options: case insensitive; ^ and $ match at line breaks

Match the characters “” literally «>»
Match the regular expression below and capture its match into
backreference with name “head_tag_innerHTML”
«(?P.*?)»
   Match any single character that is not a line break character «.*?»
  Between zero and unlimited times, as few times as possible,
expanding as needed (lazy) «*?»
Match the characters “” literally «»


Created with RegexBuddy


Escaping < > ? at the wrong time is simply a redundancy. Learning when
to escape is just like learning a new language.

You only need to escape anything if you need it to be a literal character.

e.g.

something.html vs something\.html


-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

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



RE: [PHP-DB] how does this regular expression works

2011-07-13 Thread Shahriyar Imanov
That Regex actually has an unnecessary part to it - it would be better to 
write it like:

/\(?P.*?)\<\/head\>/sim

I added /m modifier, telling it that the search is performed in Multiline 
basis. Added "head_tag_innerHTML" named reference for you, so writing this 
Regex in PHP like this:

preg_match(   '/\(?P.*?)\<\/head\>/sim'   , 
$subject  ,  $matches   )

will place search results inside $matches and you can access your captured 
content, i.e. HEAD's value in $matches['head_tag_innerHTML'].

I also replaced your delimiters for better clearance...

It will fetch EVERYTHING that comes inside HEAD tag, i.e. its value/innerHTML. 
Putting ? after * makes it to perform *ungreedy* scan. And escaping all 
possible Regex characters [including <, >, ? etc] is a good practice.


Shehi





-Original Message-
From: who@gmail.com [mailto:who@gmail.com] On Behalf Of who.cat
Sent: 13 iyul 2011 15:43
To: php-db@lists.php.net
Subject: [PHP-DB] how does this regular expression works

Reading some code from the web spider,got the such a expression :
preg_match("@]*>(.*?)<\/head>@si",$file, $regs); It's about get the 
head content of a website,i wanna know the match detail .Could someone give 
some tips , thanks in advance .

All you best

What we are struggling for ?
The life or the life ?


smime.p7s
Description: S/MIME cryptographic signature


[PHP-DB] how does this regular expression works

2011-07-13 Thread who.cat
Reading some code from the web spider,got the such a expression :
preg_match("@]*>(.*?)<\/head>@si",$file, $regs);
It's about get the head content of a website,i wanna know the match detail
.Could someone give some tips ,
thanks in advance .

All you best

What we are struggling for ?
The life or the life ?