title: Nokogiri: Searching for <div> using XPath
body: <p>I use <a href="http://github.com/tenderlove/nokogiri/tree/master" rel="noreferrer">Nokogiri</a> (Rubygem) css search to look for certain <code>&lt;div&gt;</code> inside my html. It looks like Nokogiri's css search doesn't like regex. I would like to switch to Nokogiri's <a href="http://www.w3.org/TR/xpath" rel="noreferrer">xpath</a> search as this seems to support regex in search strings.</p>
  
  <p>How do I implement the (pseudo) css search mentioned below in an xpath search?</p>
  
  <pre><code>require 'rubygems'
  require 'nokogiri'
  
  value = Nokogiri::HTML.parse(&lt;&lt;-HTML_END)
    "&lt;html&gt;
      &lt;body&gt;
        &lt;p id='para-1'&gt;A&lt;/p&gt;
        &lt;p id='para-22'&gt;B&lt;/p&gt;
        &lt;h1&gt;Bla&lt;/h1&gt;
        &lt;p id='para-3'&gt;C&lt;/p&gt;
        &lt;p id='para-4'&gt;D&lt;/p&gt;
        &lt;div class="foo" id="eq-1_bl-1"&gt;
          &lt;p id='para-5'&gt;3&lt;/p&gt;
        &lt;/div&gt;
      &lt;/body&gt;
    &lt;/html&gt;"
  HTML_END
  
  # my_block is given
  my_bl = "1"
  # my_eq corresponds to this regex
  my_eq = "\/[0-9]+\/"
  
  # FIXME The following line should be changed to an xpath search.
  if my_div = value.css("div#eq-#{my_eq}_bl-#{my_bl}.foo").first
    # doing some stuff with the &lt;p&gt; inside the div
  end
  </code></pre>