Jump to content

Pulling values out of a large piece of text based on what is before the value


smerny

Recommended Posts

"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

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?

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

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.

 

:)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.