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

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -