themodem Posted January 29, 2010 Share Posted January 29, 2010 Hi all, I have a regex which gets me the following info Titles & Actions '/((?:{module title\="((?:[a-zA-Z0-9_ ]*))" action\="((?:[a-zA-Z0-9_ ]*))"\}))/i' So if I enter {module title="Galleries" action="frontlist"} I get back. Galleries & frontlist. This is working fine but I cant work out how to get multiple paramaters back, for example if I have the following string {module title="Contact" action="getform" form="contact"} How would i get back the form part as a match. This could change dynamicly like {module title="Contact" action="getform" form="contact" anotherParamater="Foo" yetAnother="Bar"} Thanks Quote Link to comment https://forums.phpfreaks.com/topic/190266-regex-multiple-return-matches/ Share on other sites More sharing options...
akitchin Posted January 29, 2010 Share Posted January 29, 2010 one option would be to add to the pattern to match any number of non-end-brace characters so that it matches up until the end of the braced section: '/((?:{module title\="((?:[a-zA-Z0-9_ ]*))" action\="((?:[a-zA-Z0-9_ ]*))"[^}]*\}))/i' i'm not a regex guru, so you might need to escape that end brace in the character set i've added. EDIT: wasn't paying close enough attention. see JAY's post. Quote Link to comment https://forums.phpfreaks.com/topic/190266-regex-multiple-return-matches/#findComment-1003817 Share on other sites More sharing options...
JAY6390 Posted January 29, 2010 Share Posted January 29, 2010 Something like this looks like it will work '/{module title="([^"]+)" action="([^"]+)" form="([^"]+)"[^}]*}/i' Quote Link to comment https://forums.phpfreaks.com/topic/190266-regex-multiple-return-matches/#findComment-1003818 Share on other sites More sharing options...
themodem Posted January 29, 2010 Author Share Posted January 29, 2010 Excelent, I have changed it slightly to '/{module ([^"]+)="([^"]+)" ([^"]+)="([^"]+)" ([^"]+)="([^"]+)"[^}]*}/i' This returns Array ( [0] => Array ( [0] => {module title="Contact" action="getform" form="contact" another="test"} ) [1] => Array ( [0] => title ) [2] => Array ( [0] => Contact ) [3] => Array ( [0] => action ) [4] => Array ( [0] => getform ) [5] => Array ( [0] => form ) [6] => Array ( [0] => contact ) ) As the paramater field changes. Thanks all for your help. Quote Link to comment https://forums.phpfreaks.com/topic/190266-regex-multiple-return-matches/#findComment-1003849 Share on other sites More sharing options...
themodem Posted January 30, 2010 Author Share Posted January 30, 2010 Ive worked out a better way for me to do my tags however i now have a new query for you all I now have tags like {block="header"} and {block="image" src="test"} I can get regex to match {block="header"} and src="test"} but not the whole thing. For example Using the regex /(?<tag>{?(?<params>(?<paramName>[a-zA-Z0-9]+)\="(?<paramValue>[a-zA-Z0-9-_ ]+)")+}?)/ I get the following Array ( [0] => Array ( [0] => class="yellowbar" [1] => id="header" [2] => id="eyebrowNav" [3] => title="topMenu" [4] => id="navigation" [5] => title="mainMenu" [6] => class="nyroModal" [7] => class="frontLeft" [8] => class="breaker" [9] => class="nyroModal" [10] => class="frontRight" [11] => class="breaker" [12] => class="nyroModal" [13] => class="frontLeft" [14] => class="breaker" [15] => id="footer" [16] => title="bottomMenu" ) [1] => Array ( [0] => class="yellowbar" [1] => id="header" [2] => id="eyebrowNav" [3] => title="topMenu" [4] => id="navigation" [5] => title="mainMenu" [6] => class="nyroModal" [7] => class="frontLeft" [8] => class="breaker" [9] => class="nyroModal" [10] => class="frontRight" [11] => class="breaker" [12] => class="nyroModal" [13] => class="frontLeft" [14] => class="breaker" [15] => id="footer" [16] => title="bottomMenu" ) [2] => Array ( [0] => class [1] => id [2] => id [3] => title [4] => id [5] => title [6] => class [7] => class [8] => class [9] => class [10] => class [11] => class [12] => class [13] => class [14] => class [15] => id [16] => title ) [3] => Array ( [0] => yellowbar [1] => header [2] => eyebrowNav [3] => topMenu [4] => navigation [5] => mainMenu [6] => nyroModal [7] => frontLeft [8] => breaker [9] => nyroModal [10] => frontRight [11] => breaker [12] => nyroModal [13] => frontLeft [14] => breaker [15] => footer [16] => bottomMenu ) ) Which is matching the html aswell as the {} tags. What im looking for is something that will match {ID="VALUE" MULTIPLE TIMES UNTILL} is found With {DATA} being a group and all sub groups in it, if that makes any sense Thanks Quote Link to comment https://forums.phpfreaks.com/topic/190266-regex-multiple-return-matches/#findComment-1004302 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.