Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regexp problem ereg and strpos dont help 1

Status
Not open for further replies.

davidshields

Programmer
May 15, 2002
14
GB
Hokay -
strpos tells me where needle is in haystack. Lovely.
ereg tells me that regexp is in haystack (and returns it to me). Lovely.
Except...
needle is a string. How do I find the offset into a string of a bloody regexp ???
Am I being really thick, or is this hard ? I want to find something more complicated than a string, so I choose regexp, and I want to know *where* it is.
Surely I'm not the forst person to need this - after all all regexp handling editors (yes, Textpad we love you) do this.
Please put me out of my misery.
WaveyDavey.

 
davidshields,

what do you have so far? maybe seeing it in context of what you're trying to do will help me wrap my head around the problem.

inger
 
sleipnir - thanks mate - someone else pointed me at this too. Seemingly PREG_OFFSET_CAPTURE is post 4.3, and I'm using post 4.3 php, but with 4.0 manuals ! (silly me forgot to update manuals.)
 
ingernet - what I was trying to do was find out where a complicated regexp lived in a string.
strpos lets me find where simple thing is in string, and ereg lets me extract a complicated regexp (but prior to 4.3 wouldn't tell me where it was).
The annoying thing was (prior to 4.3) that ereg MUST have known where it was in the string to extract it, but was keeping it secret.
I have some complicated things to suck out from a HTML page (hence the regexp), and I want to know that some are after others (hence I needed the position in the string).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top