📜  红宝石 | StringScanner 匹配?函数

📅  最后修改于: 2022-05-13 01:55:28.244000             🧑  作者: Mango

红宝石 | StringScanner 匹配?函数

StringScanner#match?() : match?()是一个 StringScanner 类方法,用于检查给定模式是否与当前扫描指针匹配。

示例 #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 :