정규식에 대한 경험이 전혀 없으므로 제 질문입니다.
다음과 같은 문자열이 있습니다.
[1,24,2,59]
문자열은 사용자가 조작하여 변경할 수 있으므로 여전히 동일한 조직 패턴을 따르고 있으며 숫자, 대괄호 및 쉼표 만 포함하고 있는지 확인하고 싶습니다.
이 정규식을 사용 preg_match
하여 입력의 유효성을 검사 할 수 있습니다 .
'/\[\d+(,\d+)*\]/'
\[ matches the character [ literally
\d+ match a digit [0-9]
Quantifier: Between one and unlimited times, as many times as possible, giving back as
needed [greedy]
1st Capturing group (,\d+)*
Quantifier: Between zero and unlimited times, as many times as possible, giving back as
needed [greedy]
Note: A repeated capturing group will only capture the last iteration. Put a capturing
group around the repeated group to capture all iterations or use a non-capturing group
instead if you're not interested in the data
, matches the character , literally
\d+ match a digit [0-9]
Quantifier: Between one and unlimited times, as many times as possible, giving back as
needed [greedy]
\] matches the character ] literally
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다