alonso Posted January 29, 2009 Share Posted January 29, 2009 Hi! Could you help to split this string with preg_match ? $str ="Name Surname (Comment Variable) <email>" $string1 = "Name Surname" ; $string2 = "Comment Variable" ; $string3= "email" Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/142972-split-my-format-please/ Share on other sites More sharing options...
rhodesa Posted January 29, 2009 Share Posted January 29, 2009 <?php $str ="Name Surname (Comment Variable) <email>"; preg_match('/(.+?)\s+\(([^)]+)\)\s+<([^>]+)>/',$str,$matches); list(,$string1,$string2,$string3) = $matches; ?> Link to comment https://forums.phpfreaks.com/topic/142972-split-my-format-please/#findComment-749687 Share on other sites More sharing options...
alonso Posted January 29, 2009 Author Share Posted January 29, 2009 Thank you very much! and.. what if the "(Comment)" is optional in the string? Link to comment https://forums.phpfreaks.com/topic/142972-split-my-format-please/#findComment-749691 Share on other sites More sharing options...
rhodesa Posted January 29, 2009 Share Posted January 29, 2009 preg_match('/(.+?)\s+(?:\(([^)]+)\)\s+)?<([^>]+)>/',$str,$matches); list(,$string1,$string2,$string3) = $matches; Link to comment https://forums.phpfreaks.com/topic/142972-split-my-format-please/#findComment-749702 Share on other sites More sharing options...
alonso Posted January 29, 2009 Author Share Posted January 29, 2009 Thanks again! You are so kind! Link to comment https://forums.phpfreaks.com/topic/142972-split-my-format-please/#findComment-749724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.