当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Scala Regexp =~()用法及代码示例


Regexp#=~():=~() 是 Regexp 类方法,它将正则表达式与字符串进行匹配。

用法:Regexp.=~()
参数: Regexp values
Return: true - if two regular expressions matches string otherwise return false

示例#1:

红 gems


# Ruby code for Regexp.=~() method
# declaring Regexp value
reg_a = /a/
# declaring Regexp value
reg_b = /geeks/
# declaring Regexp value
reg_c = /a/
#  =~ method
puts "Regexp =~ form : #{reg_a =~ "happy"}\n\n"
puts "Regexp =~ form : #{reg_b =~ "geeksforgeeks"}\n\n"
puts "Regexp =~ form : #{reg_c =~ "goal"}\n\n"

输出:

Regexp =~ form : 1

Regexp =~ form : 0

Regexp =~ form : 2

示例#2:

红 gems


# Ruby code for Regexp.=~() method
# declaring Regexp value
reg_a = /geeks/
# declaring Regexp value
reg_b = /problem/
# declaring Regexp value
reg_c = /code/
#  =~ method
puts "Regexp =~ form : #{reg_a =~ "geeksforgeeks"}\n\n"
puts "Regexp =~ form : #{reg_b =~ "property"}\n\n"
puts "Regexp =~ form : #{reg_c =~ "codemonk"}\n\n"

输出:

Regexp =~ form : 0

Regexp =~ form : 

Regexp =~ form : 0

相关用法


注:本文由纯净天空筛选整理自mayank5326大神的英文原创作品 Ruby | Regexp =~() function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。