title: How do I use regular expressions in a Cucumber table (multiline argument) to diff against table?
body: <p>I am using a scenario table (<a href="https://github.com/cucumber/cucumber/wiki/Multiline-Step-Arguments" rel="noreferrer">multiline step arguments</a>) to check some data from a screen using cucumber, using the in built .diff! method on the Cucumber AST table.</p>
  
  <p>I would like to check the content matches against regular expressions.</p>
  
  <pre><code>Scenario: One
      Then the table appears as:
      | One   | Two   | Three |
      | /\d+/ | /\d+/ | /\d+/ |
  </code></pre>
  
  <p>The actual table could look something like</p>
  
  <pre><code>| One | Two | Three |
  | 123 | 456 | 789   |
  </code></pre>
  
  <p>which this scenario is translated to "as long as there are some digits, I don't care"</p>
  
  <p>An example step implementation that fails:</p>
  
  <pre><code>Then /^the table appears as:$/ do |expected_table|
    actual_table  = [['One','Two', 'Three'],['123', '456', '789']]
    expected_table.diff! actual_table
  end
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Then the table appears as: # features/step_definitions/my_steps.rb:230
        | One    | Two    | Three  |
        | /\\d+/ | /\\d+/ | /\\d+/ |
        | 123    | 456    | 789    |
        Tables were not identical (Cucumber::Ast::Table::Different)
  </code></pre>
  
  <p>I have tried using step transforms to transform the cells into regular expressions, but they still aren't identical.</p>
  
  <p>Transform code:</p>
  
  <pre><code> expected_table.raw[0].each do |column|
      expected_table.map_column! column do |cell|
        if cell.respond_to? :start_with?
          if cell.start_with? "/"
            cell.to_regexp
          else
            cell
          end
        else
          cell
        end
      end
    end
  </code></pre>
  
  <p>which provides the eror:</p>
  
  <pre><code>Then the table appears as: # features/step_definitions/my_steps.rb:228
        | One          | Two          | Three        |
        | (?-mix:\\d+) | (?-mix:\\d+) | (?-mix:\\d+) |
        | 123          | 456          | 789          |
        Tables were not identical (Cucumber::Ast::Table::Different)
  </code></pre>
  
  <p>Any ideas? I am stuck.</p>