i want to find the position of a regex pattern within a string. i realise i can check for the existence of the pattern with preg_match but what i really need is the position of the found match within the haystack, more like what strpos does.
In short i need a function with the exact behaviour of strpos but that works with regular expressions. can anyone help, please?
how do i find the position of a regex pattern?
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: how do i find the position of a regex pattern?
Code: Select all
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE);
echo $matches[0][1];mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: how do i find the position of a regex pattern?
that was the perfect answer to my problem. thanks man. you are too much. 