Erroneous Matches with Regular Expression
Posted
by Ballsacian1
on Stack Overflow
See other posts from Stack Overflow
or by Ballsacian1
Published on 2010-04-07T07:19:06Z
Indexed on
2010/04/07
7:23 UTC
Read the original article
Hit count: 192
$regexp = '/(?:<input\stype="hidden"\sname="){1}([a-zA-Z0-9]*)(?:"\svalue="1"\s\/>)/';
$response = '<input type="hidden" name="7d37dddd0eb2c85b8d394ef36b35f54f" value="1" />';
preg_match($regexp, $response, $matches);
echo $matches[1]; // Outputs: 7d37dddd0eb2c85b8d394ef36b35f54f
So I'm using this regular expression to search for an authentication token on a webpage implementing Joomla in order to preform a scripted login.
I've got all this working but am wondering what is wrong with my regular expression as it always returns 2 items.
Array ( [0] => [1] => 7d37dddd0eb2c85b8d394ef36b35f54f)
Also the name of the input I'm checking for changes every page load both in length and name.
© Stack Overflow or respective owner