Nuv Posted May 26, 2011 Share Posted May 26, 2011 Is my regex for the below code right ? <a href="solo.php?op=nope&c=3-024426" accesskey="W" class='nav' > My regex preg_match_all('~<a\s+href="solo.php?op=nope&c=(.*?)"\s+accesskey="W"\s+class=\'nav\'\s+>~', $continu, $walk); I need the number c=3-024426. Quote Link to comment https://forums.phpfreaks.com/topic/237513-is-my-regex-right-trying-to-capture-the-link/ Share on other sites More sharing options...
JAY6390 Posted May 26, 2011 Share Posted May 26, 2011 '~<a\s+href="solo\.php\?op=nope&([^"]+)~' Quote Link to comment https://forums.phpfreaks.com/topic/237513-is-my-regex-right-trying-to-capture-the-link/#findComment-1220510 Share on other sites More sharing options...
Nuv Posted May 26, 2011 Author Share Posted May 26, 2011 Nope that doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/237513-is-my-regex-right-trying-to-capture-the-link/#findComment-1220668 Share on other sites More sharing options...
JAY6390 Posted May 26, 2011 Share Posted May 26, 2011 That matches your supplied data just fine and outputs c=3-024426 Clearly your input data isn't the same as what you've supplied Quote Link to comment https://forums.phpfreaks.com/topic/237513-is-my-regex-right-trying-to-capture-the-link/#findComment-1220670 Share on other sites More sharing options...
xyph Posted May 26, 2011 Share Posted May 26, 2011 Try $pattern = '/(?:\?|&)c=([^"&]++)/'; This will match either ? or & followed by a c=, it will then capture everything until a double-quote or & symbol is found. Quote Link to comment https://forums.phpfreaks.com/topic/237513-is-my-regex-right-trying-to-capture-the-link/#findComment-1220699 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.