本文簡要介紹ruby語言中 String.match? 的用法。
用法
match?(pattern, offset = 0) → true or false
根據是否為 self 和 pattern 找到匹配項,返回 true 或 false。
注意:不更新 Regexp-related global variables 。
通過轉換pattern(如果還不是正則表達式)計算regexp。
regexp = Regexp.new(pattern)
如果 self+.match(regexp) 返回 Matchdata 對象,則返回 true,否則返回 false:
'foo'.match?(/o/) # => true
'foo'.match?('o') # => true
'foo'.match?(/x/) # => false
如果給出整數參數 offset,則搜索從索引 offset 開始:
'foo'.match?('f', 1) # => false
'foo'.match?('o', 1) # => true
相關用法
- Ruby String.match用法及代碼示例
- Ruby String.unpack用法及代碼示例
- Ruby String.scan用法及代碼示例
- Ruby String.dump用法及代碼示例
- Ruby String.oct用法及代碼示例
- Ruby String.size用法及代碼示例
- Ruby String.scrub用法及代碼示例
- Ruby String.to_sym用法及代碼示例
- Ruby String.chop用法及代碼示例
- Ruby String.bytesize用法及代碼示例
- Ruby String.count用法及代碼示例
- Ruby String.string <=>用法及代碼示例
- Ruby String.ascii_only?用法及代碼示例
- Ruby String.downcase用法及代碼示例
- Ruby String.capitalize用法及代碼示例
- Ruby String.length用法及代碼示例
- Ruby String.lines用法及代碼示例
- Ruby String.unicode_normalize用法及代碼示例
- Ruby String.center用法及代碼示例
- Ruby String.casecmp用法及代碼示例
- Ruby String.index用法及代碼示例
- Ruby String.each_line用法及代碼示例
- Ruby String.capitalize!用法及代碼示例
- Ruby String.swapcase用法及代碼示例
- Ruby String.setbyte用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 String.match?。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
