Regex works in a test file, not in a program (HTTP response)

I am trying to debug a regular expression, and for a living I can’t understand why it works in a test file, but not elsewhere.

I get a raw HTTP response and analyzed the section of interest:

UID:5F12F7DA-10B0-4EE3-820D-B56F0B2FC153
DTSTAMP:20120408T041113Z
CLASS:PUBLIC
CREATED:20120408T041113Z
DESCRIPTION:Testfghfghfghfghfghfghfghfghfghfghfghfghfghfghfgh
DTSTART;TZID=America/New_York:20120410T000000
DTEND;TZID=America/New_York:20120419T010000
LAST-MODIFIED:20120408T041228Z
LOCATION:Philadelphia\, PA
SEQUENCE:1
SUMMARY:Test
TRANSP:OPAQUE

Each line ends with (hex: 0D0A), which should be "\ r \ n".

The summary is called here:

$ this-> Summary = \ Extract \ Extract :: GetSummary ($ vevent);

And here is the function:

public static function GetSummary($String) {
            $re1='.*?'; # Non-greedy match on filler
            $re2='(SUMMARY)';   # Word 1
            $re3='(:)'; # Any Single Character 1
            $re4='(.*?)';   # Non-greedy match on filler
            $re5='(\r\n)';  # Any Single Character 2

            if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5."/is", $String, $matches))
            {

                $word1=$matches[1][0];
                $c1=$matches[2][0];
                $word2=$matches[3][0];
                return $word2;
            }

        }

Preg_match_all evaluates to true in my test file, but false in my program. Any ideas? Is there something about the raw string that he doesn't like, or is not copied to the test file (so I can't find it)?

+3
source share
1 answer

:

function GetSummary($String) {
  $re1='.*?';       // Non-greedy match on filler
  $re2='(SUMMARY)'; // Token
  $re3='(:)';       // Separator
  $re4='(.*?)';     // Content
  $re5='\n';        // End of line

  if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5."/is", $String, $matches))
  {
    $word1=$matches[1][0];
    $c1=$matches[2][0];
    $word2=$matches[3][0];
    return $word2;
  }
}

: http://ideone.com/zHr2X

, $ .

+3

All Articles