Ruby 关于"/" 的含义

mobiwolf · March 08, 2012 · Last by wx1452 replied at March 08, 2012 · 2186 hits

小白问题:

string = "the:rain:in:spain"
words = string.split(/:/)

一时不明 split 中的参数:,为什么要加两个 / 呢?

表示是正则表达式吧

正则表达式的字面值常量就这种写法,/RegExp/ ,后面可能还会接一些参数,如 i, m 等。

/ / 就如同字符串要用" "一样

You need to Sign in before reply, if you don't have an account, please Sign up first.