showkey
showkey

Reputation: 348

Why the Minimum matching is wrong?

<?php
    $str='00160.Day';
    $pattern = "/(.+?)('.Day')/i";
    $replacement = "\${1}";
    print preg_replace($pattern, $replacement, $str);
?>

Why the output is 00160.Day ,not 00160?What is the matter with my Minimum matching regular expression?

Upvotes: 0

Views: 42

Answers (1)

Rahul
Rahul

Reputation: 3509

Single Quote ' around day is cause of unexpected output. . should also be escaped. Use below pattern.

"/(.+?)(\.Day)/i";

Upvotes: 4

Related Questions