regex - Ruby parse string with regular expressions -
if have string this: [3 series] 315
, how can parse generate substrings series="3 series" , model="315" using regexp in ruby? correct way it:
"[3 series] 315".split /[|\]\s/
series can string or number
_, series, model = "[3 series] 315".scan(/(\d+\s\w+|\d+)/)
or
_, series, model = "[3 series] 315".split /\[|\]\s/ series # => "3 series" model # => "315"
Comments
Post a Comment