本文簡要介紹ruby語言中 URI.regexp
的用法。
用法
regexp(schemes = nil)
概要
URI::regexp([match_schemes])
參數
match_schemes
-
Array
個方案。如果給定,則生成的正則表達式與方案為 match_schemes 之一的 URI 匹配。
說明
返回與 URI-like 字符串匹配的 Regexp
對象。此方法返回的 Regexp
對象包括任意數量的捕獲組(括號)。永遠不要依賴它的數量。
用法
require 'uri'
# extract first URI from html_string
html_string.slice(URI.regexp)
# remove ftp URIs
html_string.sub(URI.regexp(['ftp']), '')
# You should not rely on the number of parentheses
html_string.scan(URI.regexp) do |*matches|
p $&
end
相關用法
- Ruby URI.parse用法及代碼示例
- Ruby URI.join用法及代碼示例
- Ruby URI.decode_www_form用法及代碼示例
- Ruby URI.extract用法及代碼示例
- Ruby URI.encode_www_form用法及代碼示例
- Ruby URI.split用法及代碼示例
- Ruby URI模塊用法及代碼示例
- Ruby UndefinedConversionError.source_encoding用法及代碼示例
- Ruby UnboundMethod.original_name用法及代碼示例
- Ruby UID.change_privilege用法及代碼示例
- Ruby Util.unescape用法及代碼示例
- Ruby Util.url_encode用法及代碼示例
- Ruby UNIXSocket.new用法及代碼示例
- Ruby UNIXSocket.addr用法及代碼示例
- Ruby UnboundMethod.bind用法及代碼示例
- Ruby UNIXServer.accept用法及代碼示例
- Ruby UNIXSocket.recv_io用法及代碼示例
- Ruby UID.euid用法及代碼示例
- Ruby UncaughtThrowError類用法及代碼示例
- Ruby Util.pretty用法及代碼示例
- Ruby UID.uid用法及代碼示例
- Ruby UnwindDetails.all_requirements用法及代碼示例
- Ruby UnboundMethod類用法及代碼示例
- Ruby UnwindDetails.reversed_requirement_tree_index用法及代碼示例
- Ruby UnboundMethod.parameters用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 URI.regexp。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。