[Ruby-0]正则表达式(regular expression)
[Ruby-0]正则表达式(regular expression)=~范围(Range)缩写(shorthand syntax)修饰语(Modifier)获取匹配部分的字符
Ruby的正则表达式定义在两个/中,如
A.match /\d+/
=~
=~返回第一给对应到的字符的index,否则返回nil
# Find the word 'like'
"Do you like cats?" =~ /like/
如果你不在乎对应字母的index,也可以使用String#include?
范围(Range)
[
原创
2021-09-02 11:47:06 ·
341 阅读 ·
0 评论