Lukeidiot Posted August 10, 2012 Share Posted August 10, 2012 I can match this fine: type="submit" value="Login"> using this regex... preg_match_all('/name="action" value="(.*)">/', $source, $matches); However, I cannot match this: name="op3sfdkkfd" value="c90484908cc5d1b99c55f0191bba1932|1344564474"> with this: preg_match_all('/name="op3sfdkkfd" value="(.*)">/', $source, $matches); I believe the problem is that it has a "|" in the middle and is messing it up. I am trying to match this part: c90484908cc5d1b99c55f0191bba1932|1344564474 Any idea guys? Thanks in advance. I am using the script to login to my domains registration site, then change the DNS A record to a mirror site in case the server ever goes down. Quote Link to comment https://forums.phpfreaks.com/topic/266892-matching-a-string-in-quotes-with-a-in-the-middle/ Share on other sites More sharing options...
requinix Posted August 10, 2012 Share Posted August 10, 2012 I believe the problem is that it has a "|" in the middle and is messing it up. Nope. Pipes only matter when they're in the regex itself - pipes in the source text are fine. Are you sure the name isn't a random string? Quote Link to comment https://forums.phpfreaks.com/topic/266892-matching-a-string-in-quotes-with-a-in-the-middle/#findComment-1368291 Share on other sites More sharing options...
Lukeidiot Posted August 10, 2012 Author Share Posted August 10, 2012 I believe the problem is that it has a "|" in the middle and is messing it up. Nope. Pipes only matter when they're in the regex itself - pipes in the source text are fine. Are you sure the name isn't a random string? Yeah that's what I thought too, however this is not the case. Here is the actual source I am using: https://internetbs.net Quote Link to comment https://forums.phpfreaks.com/topic/266892-matching-a-string-in-quotes-with-a-in-the-middle/#findComment-1368298 Share on other sites More sharing options...
requinix Posted August 10, 2012 Share Posted August 10, 2012 Looks like they have a free API. I strongly recommend using that instead, even if only because it'll be a lot easier. Quote Link to comment https://forums.phpfreaks.com/topic/266892-matching-a-string-in-quotes-with-a-in-the-middle/#findComment-1368301 Share on other sites More sharing options...
Psycho Posted August 15, 2012 Share Posted August 15, 2012 As per your regex, the problem is in your quantifier (i.e the '*'). '/name="action" value="(.*)">/' That '.*' is telling the regex engine to find every possible character, up to the LAST instace of '">'. So it is capturing the start of the value to the very last closing tag on the page (with a parameter) in it. You need to either make the quantifier lazy by using '.*?' (which is not too efficient) or better yet, change your expression to this: '/name="action" value="([^"]*)">/' So now, after it finds the matching text at the beginning (up to the opening quote for the value) it will capture all non-quote mark characters - up to the next quote mark. So the regex will be matching/returning the content of the value parameter as you wanted. Quote Link to comment https://forums.phpfreaks.com/topic/266892-matching-a-string-in-quotes-with-a-in-the-middle/#findComment-1369513 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.