红宝石 | StringScanner 匹配?函数
StringScanner#match?() : match?()是一个 StringScanner 类方法,用于检查给定模式是否与当前扫描指针匹配。
Syntax: StringScanner.match?()
Parameter: StringScanner values
Return: position – if pattern matches otherwise return 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 :