我需要匹配所有这些开始标记:
<p>
<a href="foo">
Run Code Online (Sandbox Code Playgroud)
但不是这些:
<br />
<hr class="foo" />
Run Code Online (Sandbox Code Playgroud)
我想出了这个,并希望确保我做对了.我只抓住了a-z.
<([a-z]+) *[^/]*?>
Run Code Online (Sandbox Code Playgroud)
我相信它说:
/,然后我有这个权利吗?更重要的是,你怎么看?
我知道当你使用includes并where在连接表上指定一个子句时,你应该使用.references
例:
# will error out or throw deprecation warning in logs
customers = Customer.includes(:orders).where("Orders.cost < ?", 100)
Run Code Online (Sandbox Code Playgroud)
否则,在rails 4或更高版本中,您将收到如下错误:
Mysql2 ::错误:'where子句'中的未知列'Orders.cost':SELECT
customers.*FROMcustomersWHERE(Orders.cost <100)
或者您将收到弃用警告:
弃用警告:您似乎急于加载在字符串SQL片段中引用的表(用户,地址之一).例如:
Run Code Online (Sandbox Code Playgroud)Post.includes(:comments).where("comments.title = 'foo'")目前,Active Record识别字符串中的表,并且知道将comments表连接到查询,而不是在单独的查询中加载注释.但是,在不编写完整的SQL解析器的情况下执行此操作本身就存在缺陷.由于我们不想编写SQL解析器,因此我们将删除此功能.从现在开始,当您从字符串引用表时,必须明确告诉Active Record:
Post.includes(:comments).where("comments.title ='foo'").references(:comments)
如果您不依赖隐式连接引用,则可以通过设置完全禁用该功能
config.active_record.disable_implicit_join_references = true.(SELECT"users"."id"AS t0_r0,"users"."name"AS t0_r1,"users"."email"AS t0_r2,"users"."created_at"AS t0_r3,"users"."updated_at"AS t0_r4 ,"地址"."id"AS t1_r0,"地址"."user_id"AS t1_r1,"地址"."country"AS t1_r2,"地址"."street"AS t1_r3,"地址"."postal_code"AS t1_r4 ,"地址"."city"AS t1_r5,"地址"."created_at"AS t1_r6,"地址"."updated_at"AS t1_r7 FROM"users"LEFT OUTER JOIN"地址"ON"地址"."user_id"="用户"."id"WHERE(addresses.country ='Poland')
说得通.使用时,Rails不希望成为SQL解析器includes.因此,为了让铁路开心,我们这样做:
# No error and no deprecation warning because we are …Run Code Online (Sandbox Code Playgroud)