다음 코드는 필요한 경우에도 예상 결과를 생성하지 않습니다. 그러나 주석을 사용하고 단일 행 버전을 사용하는 패턴을 주석 처리하면 작동합니다. 문제가 무엇인지 생각해 볼 수 있습니까? 당신은 작은 따옴표로 끝나는 의견을 따옴표 안에 연결하는 후주석이있는 정규 표현식이 작동하지 않습니다.
가/^
(?=[a-zA-Z]*?\d) # Checks if the string contains at least one digit
(?=\d*?[a-zA-Z]) # Checks if the string contains at least one letter either in lower- or upper-case
[a-zA-Z\d]{ # Overall the string must consist of only digits and letters, regardless of capitalization for the latter8, # Password minimum length15} # Password maximum length
$/x
당신은 줄 바꿈이없는이의 사전 태그 결과에 패턴을 Echo'ing
define('USER_PASSWORD_MIN_LENGTH', 8);
define('USER_PASSWORD_MAX_LENGTH', 15);
$password = 'mlk45jl64pfw';
//$pattern = '/^(?=[a-zA-Z]*?\d)(?=\d*?[a-zA-Z])[a-zA-Z\d]{8,15}$/x';
///*
$pattern = '/^
(?=[a-zA-Z]*?\d) # Checks if the string contains at least one digit
(?=\d*?[a-zA-Z]) # Checks if the string contains at least one letter either in lower- or upper-case
[a-zA-Z\d]{ # Overall the string must consist of only digits and letters, regardless of capitalization for the latter'
. USER_PASSWORD_MIN_LENGTH . ', # Password minimum length'
. USER_PASSWORD_MAX_LENGTH . '} # Password maximum length
$/x';
//*/
if (preg_match($pattern, $password)) {
echo "<p>Password is valid.</p>\n";
} else {
echo "<p>Password is not valid.</p>\n";
}