Jump to content

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


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.

 

:)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.