Re: how can i lookup the index in a string where a regexp matches?

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

 



Rene Veerman wrote:
hi, i need to search with regexps in strings, and want to know the index (of the source string) at which the regexp matched. and the length of the matched string, so with substitutions like \d+..

i'm kinda in a hurry on this one, would appreciate your immediate answer very much..

:D i shouldnt scan texts to fast anymore.. esp when i'm in a hurry

http://nl.php.net/manual/en/function.preg-match.php

|<?php
$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, substr($subject,3), $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
?> |

will produce

Array
(
   [0] => Array
       (
           [0] => def
           [1] => 0
       )

)




--
--------------------------------------------------------------
Rene Veerman, creator of web2.5 CMS http://mediabeez.ws/

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