📜  红宝石 | StringScanner scan_until函数

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

红宝石 | StringScanner scan_until函数

StringScanner#scan_until() : scan_until()是一个 StringScanner 类方法,它扫描字符串直到模式匹配

示例 #1:

# Ruby code for StringScanner.scan_until() method
  
# loading StringScanner
require 'strscan'
  
# declaring StringScanner 
c = StringScanner.new("Mon Sep 12 2018 14:39")
   
# scan_until() method
c.scan_until(/\w+/)
  
puts "String Scanner result of c.scan_until() form : #{c.pos()}\n\n"
  
# scan_until() method
c.scan_until(/\s+/)
  
puts "String Scanner result of c.scan_until() form : #{c.pos()}\n\n"

输出 :

String Scanner result of c.scan_until() form : 3

String Scanner result of c.scan_until() form : 4

示例 #2:

# Ruby code for StringScanner.scan_until() method
  
# loading StringScanner
require 'strscan'
  
# declaring StringScanner 
c = StringScanner.new("h ello geeks")
   
# scan_until() method
c.scan_until(/\w+/)
  
puts "String Scanner result of c.scan_until() form : #{c.pos()}\n\n"
  
  
# scan_until() method
c.scan_until(/\s+/)
  
puts "String Scanner result of c.scan_until() form : #{c.pos()}\n\n"

输出 :

String Scanner result of c.scan_until() form : 1

String Scanner result of c.scan_until() form : 2