首页 > 解决方案 > GUID 验证正则表达式失败换行符

问题描述

我正在尝试使用以下行验证 PHP 中的 GUID。

$case_number = "088169ed-7a9d-4f78-b999-170971247642\n";
$GUID_validation_RegEx = '/^[A-Fa-f\d]{8}-[A-Fa-f\d]{4}-[A-Fa-f\d]{4}-[A-Fa-f\d]{4}-[A-Fa-f\d]{12}$/';
print(preg_match($GUID_validation_RegEx, $case_number));

它返回1 (true)

我已将问题范围缩小到以下...

^[A-Fa-f\d]{8}-[A-Fa-f\d]{4}-[A-Fa-f\d]{4}-[A-Fa-f\d]{4}-[A-Fa-f\d]{12}$

                                            ^^^ these A-F (if I remove them the new line does not match)

为什么会发生这种情况,我该如何解决?

标签: phpregex

解决方案


推荐阅读