ngreenwood6 Posted August 6, 2010 Share Posted August 6, 2010 I came up with this solution all on my own knowing no regex at all '/(\[)(adapter)(=\")(.*)(\"\])/i' All I wanted this to do was match this: [adapter=test] or this:[adapter=""]. I was just wondering if there is a better way to do this and to match it on this as well [adapter] because currently it wont match that. Link to comment https://forums.phpfreaks.com/topic/209942-help-with-expression/ Share on other sites More sharing options...
JasonLewis Posted August 6, 2010 Share Posted August 6, 2010 Something like: '/\[adapter[="]*(.*?)["]?\]/i' Should match: [adapter=test] [adapter=""] [adapter] [adapter=test] Link to comment https://forums.phpfreaks.com/topic/209942-help-with-expression/#findComment-1095806 Share on other sites More sharing options...
Adam Posted August 6, 2010 Share Posted August 6, 2010 Try: '/\[adapter(?:=")?(.*?)"?\]/i' Edit Or if you want to enable single or double quotes, but make sure they match: preg_match('/\[adapter(?:=(["\']))?(.*?)\\1\]/i', $str, $matches, PREG_OFFSET_CAPTURE) Link to comment https://forums.phpfreaks.com/topic/209942-help-with-expression/#findComment-1096009 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.