新手问题 ruby 的正则

luliangshu · 2014年04月03日 · 最后由 luliangshu 回复于 2014年04月03日 · 1989 次阅读
.page{background-image:url(http://localhost:3000/assets/material/1_backgroundImage.jpg);background-size:auto;background-position:0% 0%;background-repeat:repeat;;color:rgb(111, 78, 45);font-family:Magra}.page header{background-color:rgb(142, 191, 124);text-align:start}.page header h1{color:rgb(98, 98, 98);font-size:39px;font-family:Parisienne}.page header h2{color:rgb(100, 129, 52);font-size:30px;font-family:Cutive}.page .container{background-color:rgb(255, 245, 166);font-size:14px}.page h3{color:rgb(98, 98, 98);font-family:Parisienne}.main_page{float:none;width:880px;margin:0 auto}.main_page .container .left_element{width:560px;float:left;min-height:0px}.main_page .container .right_element{width:240px;float:right;min-height:0px}

我想从这段字符串中提取到所有 font-family 到;之间的文本 也就是 font-family 的名字

str.match(/font-family:([\w|\s|-]+)/)[1].strip

/font-family\s*:\s*(?<font>.*?)\s*[;|\}]/m

测试正则可以到这个网站 http://rubular.com/

@billy @hging @saiga 非常感谢三位 匹配出来了 帮了大忙

需要 登录 后方可回复, 如果你还没有账号请 注册新账号