2011. 4. 6.

자바 regexp 참고 예제

http://www.mkyong.com/regular-expressions/how-to-validate-image-file-extension-with-regular-expression/

이미지 필터 패턴
([^\s]+(\.(?i)(jpg|png|gif|bmp))$)

자바에서는
private static final String IMAGE_PATTERN = "([^\\s]+(\\.(?i)(jpg|png|gif|bmp))$)"
과 같이 슬래시를 2개 사용

설명
( #Start of the group #1
[^\s]+ # must contains one or more anything (except white space)
( # start of the group #2
\. # follow by a dot "."
(?i) # ignore the case sensive checking for the following characters
( # start of the group #3
jpg # contains characters "jpg"
| # ..or
png # contains characters "png"
| # ..or
gif # contains characters "gif"
| # ..or
bmp # contains characters "bmp"
) # end of the group #3
) # end of the group #2
$ # end of the string
) #end of the group #1

댓글 없음: