cordoprod Posted January 6, 2010 Share Posted January 6, 2010 Hey, I'm actually starting to understand some simple regex. But there is one thing i'm struggling with. I know how to parse simple tags and stuff. But this is the code i need to parse: var bmenuItems = [ ["Halden", "Tab01", "http://hafas.websrv05.reiseinfo.no/hafas-res/dev/nri/img/vs_rutebok/style02_2_n_icon.gif", "http://hafas.websrv05.reiseinfo.no/hafas-res/dev/nri/img/vs_rutebok/style02_2_s_icon.gif", "http://hafas.websrv05.reiseinfo.no/hafas-res/dev/nri/img/vs_rutebok/style02_2_s_icon.gif", "Oversikt for region 01 Halden", "0"], ["Sarpsborg", "Tab02", "http://hafas.websrv05.reiseinfo.no/hafas-res/dev/nri/img/vs_rutebok/style02_2_n_icon.gif", "http://hafas.websrv05.reiseinfo.no/hafas-res/dev/nri/img/vs_rutebok/style02_2_s_icon.gif", "http://hafas.websrv05.reiseinfo.no/hafas-res/dev/nri/img/vs_rutebok/style02_2_s_icon.gif", "Oversikt for region 02 Sarpsborg", "0"], ["Fredrikstad", "Tab03", "http://hafas.websrv05.reiseinfo.no/hafas-res/dev/nri/img/vs_rutebok/style02_2_n_icon.gif", "http://hafas.websrv05.reiseinfo.no/hafas-res/dev/nri/img/vs_rutebok/style02_2_s_icon.gif", "http://hafas.websrv05.reiseinfo.no/hafas-res/dev/nri/img/vs_rutebok/style02_2_s_icon.gif", "Oversikt for region 03 Fredrikstad", "0"], ["Moss", "Tab04", "http://hafas.websrv05.reiseinfo.no/hafas-res/dev/nri/img/vs_rutebok/style02_2_n_icon.gif", "http://hafas.websrv05.reiseinfo.no/hafas-res/dev/nri/img/vs_rutebok/style02_2_s_icon.gif", "http://hafas.websrv05.reiseinfo.no/hafas-res/dev/nri/img/vs_rutebok/style02_2_s_icon.gif", "Oversikt for region 04 Moss", "0"], ["Indre Østfold", "Tab05", "http://hafas.websrv05.reiseinfo.no/hafas-res/dev/nri/img/vs_rutebok/style02_2_n_icon.gif", "http://hafas.websrv05.reiseinfo.no/hafas-res/dev/nri/img/vs_rutebok/style02_2_s_icon.gif", "http://hafas.websrv05.reiseinfo.no/hafas-res/dev/nri/img/vs_rutebok/style02_2_s_icon.gif", "Oversikt for region 05 Indre Østfold", "0"], ]; I need to get out all the ones with inside ["xxxxx", For example: Halden, Sarpsborg I've tried this: $linjer = preg_match_all('/([")(\w.*)(",.*)/', $htmlCode, $linjerMatches); But when i do var_dump the output is NULL. Quote Link to comment https://forums.phpfreaks.com/topic/187470-very-simple-regex-help/ Share on other sites More sharing options...
salathe Posted January 6, 2010 Share Posted January 6, 2010 Your regular expression is malformed, it will thrown an E_WARNING (which your error reporting should be displaying!) stating as much. One way to access those values with a regular expression is: $places = array(); if (preg_match_all('/^\["([\pL ]+)",/mu', $subject, $matches)) { $places = $matches[1]; } print_r($places); The expression looks for "the start of a line, followed by the characters [", followed by one or more unicode letters or ASCII space characters (these are captured for use later), followed by the characters ",. The pattern modifiers mu ask the matching engine to use multiline mode (so ^ matches at the start of any line rather than just the start of the entire string) and UTF-8 mode (so non-ASCII characters can be matched easily). Quote Link to comment https://forums.phpfreaks.com/topic/187470-very-simple-regex-help/#findComment-989921 Share on other sites More sharing options...
cordoprod Posted January 6, 2010 Author Share Posted January 6, 2010 Thanks for the reply but unfortunatly it didn't work out. I outputs an array like this: array(2) { [0]=> array(0) { } [1]=> array(0) { } } But be aware that the HTML i posted, was not the whole parse html. It was a big website, so the first line in the HTML code wasn't the first line in the web page code. Quote Link to comment https://forums.phpfreaks.com/topic/187470-very-simple-regex-help/#findComment-989929 Share on other sites More sharing options...
cordoprod Posted January 6, 2010 Author Share Posted January 6, 2010 Ok, i figured it out by just changing some small stuff. $linjer = preg_match_all('/\["([\pL ]+)",/', $htmlCode, $linjerMatches); Thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/187470-very-simple-regex-help/#findComment-989931 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.