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. Quote 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. Quote 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. Quote 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 Quote 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. Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.