How can the PHP documentation on preg_match be utilized to better understand and troubleshoot issues with regular expressions in PHP code?

If you are encountering issues with regular expressions in your PHP code, you can refer to the PHP documentation on preg_match to better understand the function and troubleshoot any problems. This documentation provides detailed explanations of how preg_match works, along with examples and common pitfalls to avoid.

$pattern = '/^([a-zA-Z0-9_-]+)$/';
$string = 'example_string';

if (preg_match($pattern, $string)) {
    echo 'String matches the pattern.';
} else {
    echo 'String does not match the pattern.';
}