Question: I know how to use preg\_match and preg\_match\_all to find the actual matches of regex patterns in a given string, but the function that I am writing not only needs the text of the matches, but to be able to traverse the string AROUND the matches...

Therefore, I need to know the position of the match in the string, based on a regex pattern.

I can't seem to find a function similar to strpos() that allows regex...any ideas?

Answer: 
preg\_match has an optional flag, `PREG_OFFSET_CAPTURE`, that records the string position of the match's occurence in the original 'haystack'. See the 'flags' section: <http://php.net/preg_match>
With use of PREG\_OFFSET\_CAPTURE on preg\_match() you will get number of times on matches on pattern. When there is a match this will have the offset value which starts from 0.

Using this value you can call preg\_match again using offset parameter.