Example 1 — Message After Success
Run a valid match and print the last error message.
<?php
preg_match('/cat/', 'a cat');
echo preg_last_error_msg(), PHP_EOL; How It Works
- The pattern /cat/ is valid and finds a match.
- No PCRE error is stored.
- preg_last_error_msg() returns the text No error.
- This is the happy path you want in normal code.

