MySQL_Narb Posted April 15, 2014 Share Posted April 15, 2014 I need the Regex to capture everything in-between the body tags. Although, it doesn't seem to work. http://regexr.com/38n6r Any ideas Quote Link to comment https://forums.phpfreaks.com/topic/287784-why-isnt-this-regex-capturing-everything-between-the-tags/ Share on other sites More sharing options...
Jacques1 Posted April 15, 2014 Share Posted April 15, 2014 (edited) Abusing regexes to write a wacky HTML parser is crap. Where's the closing tag? That site has no flag for making "." match newlines. At least it's not documented. Edited April 15, 2014 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/287784-why-isnt-this-regex-capturing-everything-between-the-tags/#findComment-1476216 Share on other sites More sharing options...
Psycho Posted April 15, 2014 Share Posted April 15, 2014 1. The content you are matching against doesn't have a closing body tag 2. You need the 's' parameter to tell the expression to traverse multiple lines - otherwise it looks for a match on single lines only The page you are using doesn't allow you to add that flag. Try a different one (e.g. http://regex101.com/) or test it yourself. Quote Link to comment https://forums.phpfreaks.com/topic/287784-why-isnt-this-regex-capturing-everything-between-the-tags/#findComment-1476217 Share on other sites More sharing options...
MySQL_Narb Posted April 15, 2014 Author Share Posted April 15, 2014 Abusing regexes to write a wacky HTML parser is crap. Where's the closing tag? That site has no flag for making "." match newlines. At least it's not documented. 1. The content you are matching against doesn't have a closing body tag 2. You need the 's' parameter to tell the expression to traverse multiple lines - otherwise it looks for a match on single lines only The page you are using doesn't allow you to add that flag. Try a different one (e.g. http://regex101.com/) or test it yourself. Sorry, somehow the HTML I copied in must have gotten cutoff. Even when there is a closing tag, it does not get a match. And I'm actually doing this in JavaScript, and I don't think it has an HTML parser like PHP that I know of. This was the only REGEX specific section I saw, so I just posted it here. And I'll look for the "s" parameter, but I thought that was basically "m" Quote Link to comment https://forums.phpfreaks.com/topic/287784-why-isnt-this-regex-capturing-everything-between-the-tags/#findComment-1476218 Share on other sites More sharing options...
Ch0cu3r Posted April 15, 2014 Share Posted April 15, 2014 (edited) In javavscrpt there is no s flag so the dot includes newlines characters. Insead you need to use [^] to match any character not a dot Edit: Working example http://regexr.com/38n74 And I'm actually doing this in JavaScript, and I don't think it has an HTML parser like PHP that I know of. Umm, the DOM? body = document.getElementByTagName('body'); alert(body[0].innerHTML); Edited April 15, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/287784-why-isnt-this-regex-capturing-everything-between-the-tags/#findComment-1476219 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.