Ruby StringScanner match?函数
StringScanner#match?() : match?()是StringScanner类的一个方法,它检查给定的模式是否从当前的扫描指针中匹配。
语法。StringScanner.match?()
参数。StringScanner的值
返回:位置 – 如果模式匹配,否则返回false
例子 #1 :
# Ruby code for StringScanner.match?() method
# loading StringScanner
require 'strscan'
# declaring StringScanner
c = StringScanner.new("Mon Sep 12 2018 14:39")
# match?() method
puts "String Scanner match? form : #{c.match?(/\w+/)}\n\n"
# match?() method
puts "String Scanner match? form : #{c.match?(/\s+/)}\n\n"
输出:
String Scanner match? form : 3
String Scanner match? form :
例子 #2 :
# Ruby code for StringScanner.match?() method
# loading StringScanner
require 'strscan'
# declaring StringScanner
c = StringScanner.new("hellogeeks")
# match?() method
puts "String Scanner match? form : #{c.match?(/\w+/)}\n\n"
# match?() method
puts "String Scanner match? form : #{c.match?(/\s+/)}\n\n"
输出:
String Scanner match? form : 10
String Scanner match? form :