红宝石 | StringScanner scan_until函数
StringScanner#scan_until() : scan_until()是一个 StringScanner 类方法,它扫描字符串直到模式匹配
Syntax: StringScanner.scan_until()
Parameter: StringScanner values
Return: the substring up to and including the end of the match
示例 #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