Home>

$data = "< script>";
$ans = preg_replace ("/<[a-zA-Z] +. +?>/", "", $data);
print ($ans);//<script>

$data = "< script>";
$ans = preg_replace ("/<[a-zA-Z] +. +?>/", "", $data);
print ($ans);//<

We understand the behavior of ②,
In case of ①, just insert a space and you will not know why it matches the regular expression.
I know that ". +?" Is the shortest match in which any single character continues more than once
I don't know which metacharacters in the regular expression match the space.

  • Answer # 1

    Is it different from what you expect?

    ";
    $pattern = "/<[a-zA-Z] +. +?>/";
    preg_match ($pattern, $data, $match);
    print htmlspecialchars ($match [0]). "
    "; $ans = preg_replace ($pattern, "", $data); print htmlspecialchars ($ans);

    * Beginning with "<" and ending with ">" for "one or more letters" or "one or more letters"
    "<", "A", "", ">" hit in order, followed by "<" at the beginning and "scrit>" at the end
    "