Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何使用Nokogiri将正则表达式与p标记文本匹配?_Ruby_Ruby On Rails 4_Nokogiri - Fatal编程技术网

Ruby 如何使用Nokogiri将正则表达式与p标记文本匹配?

Ruby 如何使用Nokogiri将正则表达式与p标记文本匹配?,ruby,ruby-on-rails-4,nokogiri,Ruby,Ruby On Rails 4,Nokogiri,我有使用search返回的Nodeset 我想找到一个标记,其中包含“Order”或“{Income}”或“Income”或“{Income}每年”,因此我编写了一个正则表达式: /(?i)order+|(\{*income\s*\}*\w*)/ 现在我想要一个带有上述文本的标记。如何使用Nokogiri使用正则表达式执行此操作?如果您已经有了要使用正则表达式进一步搜索的节点集: re = /(?i)order+|(\{*[Ii]ncome\s*\}*\w*)/ nodes = doc.sea

我有使用
search
返回的Nodeset

我想找到一个
标记,其中包含“Order”或“{Income}”或“Income”或“{Income}每年”,因此我编写了一个正则表达式:

/(?i)order+|(\{*income\s*\}*\w*)/

现在我想要一个带有上述文本的
标记。如何使用Nokogiri使用正则表达式执行此操作?

如果您已经有了要使用正则表达式进一步搜索的
节点集

re = /(?i)order+|(\{*[Ii]ncome\s*\}*\w*)/
nodes = doc.search(…) # whatever you have already
orders = nodes.select{ |n| n.name=='p' && n.text =~ re }
但是,我会这样做:

orders = doc.xpath('//p[contains(.,"Order") or contains(.,"Income")]')

如果您已经有一个要使用正则表达式进一步搜索的
节点集

re = /(?i)order+|(\{*[Ii]ncome\s*\}*\w*)/
nodes = doc.search(…) # whatever you have already
orders = nodes.select{ |n| n.name=='p' && n.text =~ re }
但是,我会这样做:

orders = doc.xpath('//p[contains(.,"Order") or contains(.,"Income")]')

如果您已经有一个要使用正则表达式进一步搜索的
节点集

re = /(?i)order+|(\{*[Ii]ncome\s*\}*\w*)/
nodes = doc.search(…) # whatever you have already
orders = nodes.select{ |n| n.name=='p' && n.text =~ re }
但是,我会这样做:

orders = doc.xpath('//p[contains(.,"Order") or contains(.,"Income")]')

如果您已经有一个要使用正则表达式进一步搜索的
节点集

re = /(?i)order+|(\{*[Ii]ncome\s*\}*\w*)/
nodes = doc.search(…) # whatever you have already
orders = nodes.select{ |n| n.name=='p' && n.text =~ re }
但是,我会这样做:

orders = doc.xpath('//p[contains(.,"Order") or contains(.,"Income")]')

向我们展示一个HTML示例,演示您正在谈论的内容。通常,我们不使用regexp查找节点。CSS和XPath都允许我们查看标记的文本,因此这些是起点。通常,我们不使用regexp查找节点。CSS和XPath都允许我们查看标记的文本,因此这些是起点。通常,我们不使用regexp查找节点。CSS和XPath都允许我们查看标记的文本,因此这些是起点。通常,我们不使用regexp查找节点。CSS和XPath都允许我们查看标记的文本,因此这些是起点。