Jump to content

Hash Key?


shahrukh1

Recommended Posts

need to extract the hash value from this string

 

id="Qform__FormState" value="c49c31100c139a92a85a1dc37fb399c5"

 

proposed expression:

$expression = '#^([a-z0-9]{32})$#i';

 

does not work

 

tried this one as well

$expression = '#id=\"Qform__FormState\" value=\"^([a-z0-9]{32})$\"#i';

no luck either

Link to comment
https://forums.phpfreaks.com/topic/271735-hash-key/
Share on other sites

The most immediate reason why your regex is failing is because ^ and $ tell the regex engine to match the beginning and end of string. So in other words, you are telling the regex engine that the whole string must be that hash, nothing else. If you remove those anchors, you will get it to match. However... it will match any 32 alphanumeric substring within the content you are scraping. Ideally you should use a DOM parser like requinix suggested, but if you really must go the regex route, this will work and is fairly flexible:

 

$expression='#(id\s*=\s*["\']Qform__FormState["\'][^>]*)?([a-z0-9]{32})(?(1)|[^>]*id\s*=\s*["\']Qform__FormState["\'])#i';

 

This will allow for some format variation tolerances: random spacing, order of attributes, and quotes.

 

The matched hash will be in $match[2]

Link to comment
https://forums.phpfreaks.com/topic/271735-hash-key/#findComment-1398188
Share on other sites

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.