Jump to content

[SOLVED] Ahhh regex!


eddy556

Recommended Posts

Hi, I know this is most probably very very simple however no matter how hard I try I could never figure this regular expressions!

 

I have something like this:

Auth = (random text here)

 

This text is contained within another string with LOADS of other random data.  What I need is a regex which will match JUST Auth and the text following it.  At the end of the text there is no delimiters such as a full stop or anything just the end of the string.  It is a random length.

 

Many thanks and I'm pretty sure I should be able to understand once I see the answer!! :)

Link to comment
Share on other sites

Hmmm.....doesn't seem to work.  I have included the whole of the text that needs searched through:

 

SID=DQAAAIwAAADYBzOfXMgIg-QKywsJCyPM6bbx5YVkPsZQPTyaHy16Pa6uNB4RXteTVBzTXXPkKxMNNlU4YuEe3DiKYvaQMHAgh_JbJzaT5490_WvtwJwOCepSu_R4bYFyTwJe-y7CRg3MMwpVkXtwaf-8vbznovVBbjSzRDp7kRpdWW1TXtOlDD_Vn-G1-cTHRMyA25wlypI

LSID=DQAAAI4AAAB1kKq-YnO_nW0K0EbSClfLvU5ZICX-12eQluWMdNLMFVkcUYREwf88uCGuqHVfJAgNvJNB-f6sJg4g1TkO11RhADnL25OR8cuh8ZayssClsjlQh-2NenhdcQzX83Vfjvq1oxbSERlhfNGR88Hoy_DquC5KWF8saxjrvdeGVaLu-CktIDnTwtmd3Ozv_TxxXiM

Auth=DQAAAI0AAAB1kKq-YnO_nW0K0EbSClfLvU5ZICX-12eQluWMdNLMFVkcUYREwf88uCGuqHVfJAgNvJNB-f6sJg4g1TkO11RhpaLcYAjO4yvGhZbl93gru4A4LtlXFRtqPNHItkoc_EyttT0-2cT81jxRjuX5qQJjmYEAYPmW4N0zYGVIJm1j84PlMdxZfuakFeEGAwjuXxE

 

 

I am trying to extract the Auth=

 

Many thanks!

Link to comment
Share on other sites

<?php
$string = <<<DATA
SID=DQAAAIwAAADYBzOfXMgIg-QKywsJCyPM6bbx5YVkPsZQPTyaHy16Pa6uNB4RXteTVBzTXXPkKxMNNlU4YuEe3DiKYvaQMHAgh_JbJzaT5490_WvtwJwOCepSu_R4bYFyTwJe-y7CRg3MMwpVkXtwaf-8vbznovVBbjSzRDp7kRpdWW1TXtOlDD_Vn-G1-cTHRMyA25wlypI
LSID=DQAAAI4AAAB1kKq-YnO_nW0K0EbSClfLvU5ZICX-12eQluWMdNLMFVkcUYREwf88uCGuqHVfJAgNvJNB-f6sJg4g1TkO11RhADnL25OR8cuh8ZayssClsjlQh-2NenhdcQzX83Vfjvq1oxbSERlhfNGR88Hoy_DquC5KWF8saxjrvdeGVaLu-CktIDnTwtmd3Ozv_TxxXiM
Auth=DQAAAI0AAAB1kKq-YnO_nW0K0EbSClfLvU5ZICX-12eQluWMdNLMFVkcUYREwf88uCGuqHVfJAgNvJNB-f6sJg4g1TkO11RhpaLcYAjO4yvGhZbl93gru4A4LtlXFRtqPNHItkoc_EyttT0-2cT81jxRjuX5qQJjmYEAYPmW4N0zYGVIJm1j84PlMdxZfuakFeEGAwjuXxE
DATA;
$matches = array();
preg_match('/Auth=(.+)$/im', $string, $matches);
print_r($matches);
?>

 

EDIT: Accidentally put 's' instead of 'i' for the modifier.

Link to comment
Share on other sites

Ah, but it does:

 

<pre>
<?php
$string = <<<DATA
SID=DQAAAIwAAADYBzOfXMgIg-QKywsJCyPM6bbx5YVkPsZQPTyaHy16Pa6uNB4RXteTVBzTXXPkKxMNNlU4YuEe3DiKYvaQMHAgh_JbJzaT5490_WvtwJwOCepSu_R4bYFyTwJe-y7CRg3MMwpVkXtwaf-8vbznovVBbjSzRDp7kRpdWW1TXtOlDD_Vn-G1-cTHRMyA25wlypI
LSID=DQAAAI4AAAB1kKq-YnO_nW0K0EbSClfLvU5ZICX-12eQluWMdNLMFVkcUYREwf88uCGuqHVfJAgNvJNB-f6sJg4g1TkO11RhADnL25OR8cuh8ZayssClsjlQh-2NenhdcQzX83Vfjvq1oxbSERlhfNGR88Hoy_DquC5KWF8saxjrvdeGVaLu-CktIDnTwtmd3Ozv_TxxXiM
Auth=DQAAAI0AAAB1kKq-YnO_nW0K0EbSClfLvU5ZICX-12eQluWMdNLMFVkcUYREwf88uCGuqHVfJAgNvJNB-f6sJg4g1TkO11RhpaLcYAjO4yvGhZbl93gru4A4LtlXFRtqPNHItkoc_EyttT0-2cT81jxRjuX5qQJjmYEAYPmW4N0zYGVIJm1j84PlMdxZfuakFeEGAwjuXxE
DATA;
preg_match('/Auth=.*/', $string, $matches);
print_r($matches);
?>
</pre>

Link to comment
Share on other sites

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.