Jerred121 Posted February 24, 2011 Share Posted February 24, 2011 Here is the code with the subject ($str) and the pattern that I started with - I've tried a lot of variations but I can't get it grab all of the variables that I need, so I figured I'd post what I started with: $str = " Intervention: Airway-Intubation of Existing Tracheostomy Stoma successful Intervention: CPR-Start Compressions only without Ventilation Intervention: CPR-Start Compressions only without Ventilation - 12:30 AM successful Intervention: Activation-Fire Rehabilitation Specialty Service/Response Team not successful Intervention: Blood Glucose Analysis - 2:30 PM not successful Intervention: Venous Access-Femoral Line successful"; $ptn = "/Intervention: *(.+) *-+? *(([0-2]*[0-9]+:[0-5]+[0-9] *(??:A|P)M)))* *((?:not )?successful)*/"; preg_match_all($ptn, $str, $CZprocedures); echo"<pre>"; print_r($CZprocedures); echo"</pre"; Here is the output from above: Array ( [0] => Array ( [0] => Intervention: Airway- [1] => Intervention: CPR- [2] => Intervention: CPR-Start Compressions only without Ventilation - 12:30 AM successful [3] => Intervention: Activation- [4] => Intervention: Blood Glucose Analysis - 2:30 PM not successful [5] => Intervention: Venous Access- ) [1] => Array ( [0] => Airway [1] => CPR [2] => CPR-Start Compressions only without Ventilation [3] => Activation [4] => Blood Glucose Analysis [5] => Venous Access ) [2] => Array ( [0] => [1] => [2] => 12:30 AM [3] => [4] => 2:30 PM [5] => ) [3] => Array ( [0] => [1] => [2] => 12:30 AM [3] => [4] => 2:30 PM [5] => ) [4] => Array ( [0] => [1] => [2] => successful [3] => [4] => not successful [5] => ) ) I need it to grab the name of the procedure (CPR-Start Compressions only without Ventilation, Blood Glucose Analysis, etc) then the time if there is one and then the result part at the end (((?:not )?successful)) if there is one. Few notes: The only thing I can count on being there is the name The hyphens in names was screwing me up (ie: Airway-Intubation of Existing Tracheostomy Stoma would end up being: Airway) Thanks for any help - it is greatly appreciated! Quote Link to comment Share on other sites More sharing options...
requinix Posted February 24, 2011 Share Posted February 24, 2011 Try /^Intervention: ((?:\S+| (?!- \d+:\d+ [AP]M|(?:not )?successful))+)(?: - (\d+:\d+ [AP]M))?(( not)? successful)?/m $str = " Intervention: Airway-Intubation of Existing Tracheostomy Stoma successful Intervention: CPR-Start Compressions only without Ventilation Intervention: CPR-Start Compressions only without Ventilation - 12:30 AM successful Intervention: Activation-Fire Rehabilitation Specialty Service/Response Team not successful Intervention: Blood Glucose Analysis - 2:30 PM not successful Intervention: Venous Access-Femoral Line successful"; $regex = '/^Intervention: ((?:\S+| (?!- \d+:\d+ [AP]M|(?:not )?successful))+)(?: - (\d+:\d+ [AP]M))?(( not)? successful)?/m'; preg_match_all($regex, $str, $matches, PREG_SET_ORDER); $array = array(); foreach ($matches as $match) { $array[] = array( "procedure" => $match[1], "time" => (empty($match[2]) ? null : $match[2]), "result" => (empty($match[3]) ? null : empty($match[4])) ); } Quote Link to comment Share on other sites More sharing options...
Jerred121 Posted February 24, 2011 Author Share Posted February 24, 2011 Your good and that was quick! thank you so much, the people on this forum are awesome! Quote Link to comment 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.