Complex regex (php) parsing phrases

I am attempting to parse speech that is part of a phone acceptance dialogue which changes in specificity depending on the phone vendor but generally has the same elements.

Here are two examples of strings I want to evaluate, one which succeeds, the other being problematic.

$speechPossibilites = [
           ["phrase" => "This is a call from Frank Bother an inmate at Washington department of corrections.
            To accept this call press three now. To reject this call press six now. To permanently block this 
            number press six. Thank you for using Securus.",
                "unit" => "Washington department of corrections",
                'dtmf' => 3],

            ["phrase" => "hello, you have received a free call from John Smith, an inmate at
                         oregon department of corrections you will not be charged for this call to accept this free call,
                         please press one now. to reject this call, please press five now.",
                "unit" => "Oregon Department of Corrections",
                "dtmf" => 1]
];

These phrases are played when a prison inmate initiates a call to somebody outside the prison. I've transcribed them and put them into a unit test to make sure I can capture important information - specifically the tone needed to allow for call acceptance automation. The 'correct' answers (unit, dtmf) are included in the phrase array so I can verify that my regex captured what I expect.

I have no problem capturing the acceptance and rejection tones. But I'd really like to capture the name of the prison system that is calling and the name of the caller. The problem is that the software which transcribes this dialogue sometimes doesn't include punctuation. Were it consistent I wouldn't have the problem.

The test routine looks like this:

       foreach ($speechPossibilities as $phrase) {
            $unit = $this->function->parseUnitData($phrase['phrase']);
            self::assertEquals(ucwords($phrase['unit'] . " (Auto Connect)"), $unit['Facility_Name']);
            #self::assertEquals($phrase['dtmf'], $unit['DTMF_Acceptance_Tone']);
        }
    }

Inside the function parseUnitData() I use this regex to capture the unit and dtmf:

        $regex = "/from(.*?)\san.*?at\s(.*?)\\.\s(.*?)to(.*?)(press|dial|select|push)\s(.*?)to(.*?)(press|dial|select|push)\s(\w).*?/i";

The problem arises when the period does not appear at the end of the unit name. No match occurs and nothing then is captured. Removing the stop on period has some not so good side effects. Either the unit name includes a lot of text that I don't want, or nothing at all is matched and the whole operation fails. But I can't seem to figure out an optional alternative. When I modify the regex and remove the search for a period:

        $regex = "/from(.*?)\san.*?at\s(.*?)\s(.*?)to(.*?)(press|dial|select|push)\s(.*?)to(.*?)(press|dial|select|push)\s(\w).*?/i";

The unit name only includes the first word in the phrase I am trying to capture. I tried using (\w{4}) as a replacement for (\\.) but this results in no match at all.

I have a fallback option which is to simplify the regex and just seek out the acceptance and rejection tones and supply my own unit name (Unknown Correctional Facility - or similar). But I thought I'd run this by the smarty pants regex experts here to see if it was possible to do what I want with a regular expression.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum