Anti-Moronic Posted May 25, 2009 Share Posted May 25, 2009 Here's my regex: preg_match("#\">(.*?)</a>#", $match[0][0], $name); But it is bringing through "> - yet not </a>. Anybody know why, and is there a simple way to tell it to not bring this through? Thanks. Link to comment https://forums.phpfreaks.com/topic/159610-solved-simple-regex-how-to-tell-it-not-to-fetch-something/ Share on other sites More sharing options...
.josh Posted May 25, 2009 Share Posted May 25, 2009 post example content of what you're trying to match and what you want the resulting match to be. Link to comment https://forums.phpfreaks.com/topic/159610-solved-simple-regex-how-to-tell-it-not-to-fetch-something/#findComment-841841 Share on other sites More sharing options...
Anti-Moronic Posted May 25, 2009 Author Share Posted May 25, 2009 No probs... This is the string to obtain the match from: ">hello, I am a string</a> with the current pattern, I am receiving: ">hello, I am a string Yet I want to receive: hello, I am a string Thanks. Link to comment https://forums.phpfreaks.com/topic/159610-solved-simple-regex-how-to-tell-it-not-to-fetch-something/#findComment-841845 Share on other sites More sharing options...
Anti-Moronic Posted May 25, 2009 Author Share Posted May 25, 2009 I sussed it out finally. Maybe not the best way, but the only way I could find. I simply tagged the group: #\">(?<tag>(.*?))</a># then, to retrieve, used: $name['tag']; Didn't even know php allowed tagging. Very happy Link to comment https://forums.phpfreaks.com/topic/159610-solved-simple-regex-how-to-tell-it-not-to-fetch-something/#findComment-841946 Share on other sites More sharing options...
.josh Posted May 25, 2009 Share Posted May 25, 2009 hmm...perhaps you were just looking at the wrong $name array element to begin with? $name[0] is the full match array, $name[1] is the first captured match array. So for instance, $name[1][0] would be the first captured match. Link to comment https://forums.phpfreaks.com/topic/159610-solved-simple-regex-how-to-tell-it-not-to-fetch-something/#findComment-841959 Share on other sites More sharing options...
Anti-Moronic Posted May 26, 2009 Author Share Posted May 26, 2009 Ahh..very possible. I was using [0][0] and [0][1] etc. Anyway, the tagging fixed it for me, and I find it far simpler. Link to comment https://forums.phpfreaks.com/topic/159610-solved-simple-regex-how-to-tell-it-not-to-fetch-something/#findComment-841992 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.