나는 이것이 인 것을 알고있는 파일 중 하나를 다운로드하지 않고 다운로드를 취소 할 수 있습니다 오래된 질문이지만이 질문을 보는 사람들에게 도움이 될 수 있습니다.
url 내에서 파일 이름의 확장자를 가져 오는 가장 좋은 방법은 매개 변수와 함께 정규식을 사용하는 것입니다.
당신은이 패턴 (하지 URL을 전용) 사용할 수 있습니다
이
.+(\.\w{3})\?*.*
설명 :
이
.+ Match any character between one and infinite
(...) With this you create a group, after you can use for getting string inside the brackets
\. Match the character '.'
\w Matches any word character equal to [a-zA-Z0-9_]
\?* Match the character '?' between zero and infinite
.* Match any character between zero and infinite
예 :
http://example.com/file.png
http://example.com/file.png?foo=10
But if you have an url like this:
http://example.com/asd
This take '.com' as extension.
그래서 당신이 같은 URL에 대한 강한 패턴을 사용할 수 있습니다 this :
.+\/{2}.+\/{1}.+(\.\w+)\?*.*
설명 :
.+ Match any character between one and infinite
\/{2} Match two '/' characters
.+ Match any character between one and infinite
\/{1} Match one '/' character
.+ Match any character between one and infinite
(\.\w+) Group and match '.' character and any word character equal to [a-zA-Z0-9_] from one to infinite
\?* Match the character '?' between zero and infinite
.* Match any character between zero and infinite
예 :
http://example.com/file.png (Match .png)
https://example.com/file.png?foo=10 (Match .png)
http://example.com/asd (No match)
C:\Foo\file.png (No match, only urls!)
http://example.com/file.png
http: .+
// \/{2}
example.com .+
/ \/{1}
file .+
.png (\.\w+)
안녕
당신의 마지막 위치를 얻으려고 수 있을까?. 발견되면,의 마지막 위치를 찾으십시오. 그 사이에 모든 것을 반환합니다. 없다면? 마지막 위치 이후에 오는 것은 무엇이든간에 발견된다. 파일 확장자가됩니다. – Crono
하위 문자열이 작동해야합니다. 길이가 3보다 큰 확장을 고려해야합니다. – Neolisk
은 URL을 제공하는 것입니까? 그들은 자신의 사이트 또는 타사 사이트에 있습니까? –