smerny Posted February 9, 2012 Share Posted February 9, 2012 "vid":"066U0000000UG0I" "csrf":"XpN.tQFYKrcAay1y6N1kSkg01QU.z9z2iV03dP_ukwA3SHZJ.uslyqrth.nmX_gAQDt1U.k4Vui3uinpULS.MjKVrXX8ifrU9hZ8MqxaCBau7uxhzKcJttctsXkyfdRus2BQtHr8g.u2v_nDOCPGWCgIvY4=" __sfdcSessionId = '00DU0000000HgD9!ARgAQMPKwJ6Q.kqAWj4M0ikwvii9RTnvxGMD4mw3BV9VIT9xs3ywp6.TwCEet6s8rU.f7lKMLl8AjJ9D_cyDSkllEJh783ux'; ---- i'd like to have 3 different regexes for these, to get the alpha/numeric/specialChar within the ' or "s after those certain identifiers Quote Link to comment https://forums.phpfreaks.com/topic/256763-pulling-values-out-of-a-large-piece-of-text-based-on-what-is-before-the-value/ Share on other sites More sharing options...
AyKay47 Posted February 9, 2012 Share Posted February 9, 2012 so you want the regex to grab 2 separate sets of characters, a set with the alphanumeric characters between the quotes, and a set of the non-alphanumeric characters between the quotes, correct? Quote Link to comment https://forums.phpfreaks.com/topic/256763-pulling-values-out-of-a-large-piece-of-text-based-on-what-is-before-the-value/#findComment-1316282 Share on other sites More sharing options...
smerny Posted February 9, 2012 Author Share Posted February 9, 2012 say this is the text: "vid":"066U0000000UG0I" "blahblah":"blah""csrf":"XpN.tQFYKrcAay1y6N1kSkg01QU.z9z2iV03dP_ukwA3SHZJ. uslyqrth.nmX_gAQDt1U.k4Vui3uinpULS.MjKVrXX8ifrU9h Z8MqxaCBau7uxhzKcJttctsXkyfdRus2BQtHr8g.u2v_nDOCP GWCgIvY4=" __sfdcSessionId = '00DU0000000HgD9!ARgAQMPKwJ6Q.kqAWj4M0ikwvii9RTnvxGMD4mw3BV9VIT9xs 3ywp6.TwCEet6s8rU.f7lKMLl8AjJ9D_cyDSkllEJh783ux'; and there will be much more text around and in between those. one regex should return: 066U0000000UG0I another: XpN.tQFYKrcAay1y6N1kSkg01QU.z9z2iV03dP_ukwA3SHZJ. uslyqrth.nmX_gAQDt1U.k4Vui3uinpULS.MjKVrXX8ifrU9h Z8MqxaCBau7uxhzKcJttctsXkyfdRus2BQtHr8g.u2v_nDOCP GWCgIvY4= and the last: 00DU0000000HgD9!ARgAQMPKwJ6Q.kqAWj4M0ikwvii9RTnvxGMD4mw3BV9VIT9xs 3ywp6.TwCEet6s8rU.f7lKMLl8AjJ9D_cyDSkllEJh783ux Quote Link to comment https://forums.phpfreaks.com/topic/256763-pulling-values-out-of-a-large-piece-of-text-based-on-what-is-before-the-value/#findComment-1316288 Share on other sites More sharing options...
ragax Posted February 9, 2012 Share Posted February 9, 2012 Hi Smerny, Try this: Code: <?php $string='"vid":"066U0000000UG0I" "blahblah":"blah""csrf":"XpN.tQFYKrcAay1y6N1kSkg01QU.z9z2iV03dP_ukwA3SHZJ. uslyqrth.nmX_gAQDt1U.k4Vui3uinpULS.MjKVrXX8ifrU9h Z8MqxaCBau7uxhzKcJttctsXkyfdRus2BQtHr8g.u2v_nDOCP GWCgIvY4=" __sfdcSessionId = \'00DU0000000HgD9!ARgAQMPKwJ6Q.kqAWj4M0ikwvii9RTnvxGMD4mw3BV9VIT9xs 3ywp6.TwCEet6s8rU.f7lKMLl8AjJ9D_cyDSkllEJh783ux\';'; $regex[0]=',"vid":"([^"]+),'; $regex[1]=',"csrf":"([^"]+),'; $regex[2]=",__sfdcSessionId\s*=\s*'([^']+),"; foreach ($regex as $r) { preg_match($r, $string, $m); echo $m[1].'<br />'; } ?> Output: 066U0000000UG0I XpN.tQFYKrcAay1y6N1kSkg01QU.z9z2iV03dP_ukwA3SHZJ. uslyqrth.nmX_gAQDt1U.k4Vui3uinpULS.MjKVrXX8ifrU9h Z8MqxaCBau7uxhzKcJttctsXkyfdRus2BQtHr8g.u2v_nDOCP GWCgIvY4= 00DU0000000HgD9!ARgAQMPKwJ6Q.kqAWj4M0ikwvii9RTnvxGMD4mw3BV9VIT9xs 3ywp6.TwCEet6s8rU.f7lKMLl8AjJ9D_cyDSkllEJh783ux Pls let me know if this works for you. If it is not matching in some cases, it means you have variation in your format (e.g. extra spaces, or different delimiters). Just post these problem cases, and I (or whoever is watching the board at that time) should be able to fix it. Quote Link to comment https://forums.phpfreaks.com/topic/256763-pulling-values-out-of-a-large-piece-of-text-based-on-what-is-before-the-value/#findComment-1316325 Share on other sites More sharing options...
smerny Posted February 9, 2012 Author Share Posted February 9, 2012 seems good thanks nice regex tutorial site btw Quote Link to comment https://forums.phpfreaks.com/topic/256763-pulling-values-out-of-a-large-piece-of-text-based-on-what-is-before-the-value/#findComment-1316330 Share on other sites More sharing options...
ragax Posted February 9, 2012 Share Posted February 9, 2012 Glad it works! And thanks for the compliment. Quote Link to comment https://forums.phpfreaks.com/topic/256763-pulling-values-out-of-a-large-piece-of-text-based-on-what-is-before-the-value/#findComment-1316339 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.