2012-09-25 4 views
0

전체 날짜 문자열을 나타내는 문자열 (스페인어로 쓰여 있음)의 유효성을 검사하기 위해 정규 표현식을 사용해야합니다 ... 실제 올해 2000 다음 큰스페인어로 된 날짜를 나타내는 문자열과 일치하는 정규식

23 de septiembre del 2003 

23 de septiembre de 1965 

경우, 단어가 '델'은 이전에 사용이 : 문자열이 유효한 날짜 (윤년 등)

문자열은 다음과 같습니다이다 년, 만약에 낱말 "de"가 사용 ...

나는 나의 연구를하고 f

$pattern = ([0-9]+); 

가 .. 그 다음 내가 그것을 모두 함께 넣어하는 방법을 잃었어요 ...

도움말 : 2 자리 IRST!

+1

~ ((\ d를 {1 등의 유효 개월의 목록을 지정할 수 있습니다 , 2}) de ([az] +) (del?) (\ d {4})) ~ –

답변

2
/\b\d{1,2} de [a-z]+ (de 1\d{3}|del 2\d{3})/i 

설명 :

\b    ... requires a word boundary, since the following character is a digit 
        (and thus a word character) this will only match if the date is 
        preceded by a character that is not a letter, not a digit and 
        not an underscore 
\d{1,2}   ... one or two digits 
de    ... literally "de" 
[a-z]+   ... any letter from a-z, at least once but an arbitrary number of times 
(de 1\d{3}  ... literally "de" followed by "1" and 3 more digits 
|    ... or 
del 2\d{3})  ... literally "del" followed by "2" and 3 more digits 

i    ... make the whole thing case-insensitive (you can omit this if needed) 

는 또한 정규식의 모든 공간이 다른 모든 문자처럼 취급되는 것을주의.

또는 대신 [a-z]+의 당신은

/\b\d{1,2} de (...|septiembre|...) (de 1\d{3}|del 2\d{3})/i 

(구분하기 위해 더 많은 달 이름으로 ... | 교체)

+0

'234 de enero del 2003'이 일치합니다 ... 첫 번째 부분이 3 자리 ? 왜? – Marco

+0

어쩌면 PHP는 숫자가 아니라 문자열로 보시겠습니까? – Marco

+1

@Marco 오, 알았어. 그것은 단지 "34"와 일치하고 2.를 무시하기 때문에 일치합니다. 앞면에 단어 경계를 추가 할 수 있습니다 (나는 그것을 대답으로 편집합니다) –

관련 문제