Regexp#compile():compile()是Regexp類方法,可完成新的正則表達式。
用法:Regexp.compile()
參數:正則表達式值
返回:創建一個新的正則表達式。
示例1:
# Ruby code for Regexp.compile() method
# declaring Regexp value
reg_a = Regexp.compile(/a/)
# declaring Regexp value
reg_c = Regexp.compile('\*?{}.')
# compile method
puts "Regexp compile form : #{reg_a}\n\n"
puts "Regexp compile form : #{reg_c}\n\n"
輸出:
Regexp compile form : (?-mix:a) Regexp compile form : (?-mix:\*?{}.)
示例2:
# Ruby code for Regexp.compile() method
# declaring Regexp value
reg_a = Regexp.compile(/geeks/)
# declaring Regexp value
reg_b = Regexp.compile('/(?<geeks>.)(?<for>.)(?<geeks>.)/')
# declaring Regexp value
reg_c = Regexp.compile('\*?????{}.')
# compile method
puts "Regexp compile form : #{reg_a}\n\n"
puts "Regexp compile form : #{reg_b}\n\n"
puts "Regexp compile form : #{reg_c}\n\n"
Regexp compile form : (?-mix:geeks) Regexp compile form : (?-mix:\/(?.)(?.)(?.)\/) Regexp compile form : (?-mix:\*?????{}.)
相關用法
- Ruby Regexp new()用法及代碼示例
- Scala Regexp ===()用法及代碼示例
- Scala Regexp =~()用法及代碼示例
- Ruby Regexp eql?()用法及代碼示例
- Scala Regexp ==()用法及代碼示例
- Ruby Regexp options()用法及代碼示例
- Ruby Regexp escape()用法及代碼示例
- Ruby Regexp quote()用法及代碼示例
- Ruby Regexp inspect()用法及代碼示例
- Ruby Regexp casefold?()用法及代碼示例
- Ruby Regexp hash()用法及代碼示例
- Ruby Regexp fixed_encoding?()用法及代碼示例
- Ruby Regexp encoding()用法及代碼示例
- Ruby Regexp to_s()用法及代碼示例
- Ruby Regexp match()用法及代碼示例
注:本文由純淨天空篩選整理自mayank5326大神的英文原創作品 Ruby | Regexp compile() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。