I'll offer you such a regular season:
~value="(.*?)"~
It will work. *?
- any number of characters (in our case any), but as little as possible (that is, before the first "
)
All code below. There's a tricky regular expression:
~<(?:.*?)value="(.*?)"(?:.*?)>~s
It describes the search only inside tags, and the s
modifier allows you to search in multi-line text. Look here at the https://regex101.com/r/qB9gS3/1 site tells in detail what's what (truth in English).
$str = '<input type="hidden" id="tracking__token" name="tracking[_token]" class="form-control" value="AJKY99B2mC__AP7vPza111" >'; preg_match_all('~<(?:.*?)value="(.*?)"(?:.*?)>~s', $str, $matches); $i = 0; foreach ($matches as $match) { foreach ($match as $item) { echo "$i: ", htmlentities($item), "<br>"; } $i++; }
Conclusion:
0: <input type="hidden" id="tracking__token" name="tracking[_token]" class="form-control" value="AJKY99B2mC__AP7vPza111" > 1: AJKY99B2mC__AP7vPza111
UPD: you can still add a space '~<(?:.*?)\svalue="(.*?)"(?:.*?)>~s'