jumpfroggy Posted May 5, 2008 Share Posted May 5, 2008 I have a $subject, and a regular-expression search string $pattern. I want to find the position of the first match of $pattern in $subject. Basically, I want a strpos() that works with regular expressions. If I do preg_match($pattern, $subject), it will return 0 (for no match) or 1 (for match found), but no position. If I do preg_match($pattern, $subject, $matches), then I'll get an array of matches in $matches, but no positions. Is there any way to do this? Thanks! Link to comment https://forums.phpfreaks.com/topic/104166-solved-how-do-i-find-the-position-of-a-regex-match/ Share on other sites More sharing options...
GingerRobot Posted May 5, 2008 Share Posted May 5, 2008 Tried looking in the manual? The 4th parameter is what you need. Link to comment https://forums.phpfreaks.com/topic/104166-solved-how-do-i-find-the-position-of-a-regex-match/#findComment-533283 Share on other sites More sharing options...
jumpfroggy Posted May 5, 2008 Author Share Posted May 5, 2008 Tried looking in the manual? The 4th parameter is what you need. Thanks for catching that, I looked at the pages for each of the preg_* functions a few times, managed to gloss over that one key line. Stupid of me. Link to comment https://forums.phpfreaks.com/topic/104166-solved-how-do-i-find-the-position-of-a-regex-match/#findComment-533290 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.