title: pivot_longer with names_pattern and pairs of columns
body: <p>I am trying to figure out how to use <code>pivot_longer</code> from <code>tidyr</code> in the following example. This is how the original table called <code>dat_plot</code> is structured like:</p>
  <pre><code>   year organizational_based action_based ideological_based share_org_based share_ideo_based share_act_based
    &lt;dbl&gt;                &lt;dbl&gt;        &lt;dbl&gt;             &lt;dbl&gt;           &lt;dbl&gt;            &lt;dbl&gt;           &lt;dbl&gt;
  1  1956                    1            0                 0               2               95              95
  2  2000                    0            0                 0              92               87              91
  </code></pre>
  <p>also here:</p>
  <pre><code>dat_plot &lt;- structure(list(year = c(1956, 2000), organizational_based = c(1, 
  0), action_based = c(0, 0), ideological_based = c(0, 0), share_org_based = c(2, 
  92), share_ideo_based = c(95, 87), share_act_based = c(95, 91
  )), row.names = c(NA, -2L), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;
  ))
  </code></pre>
  <p>I would like to turn it into the long format, in the following way:</p>
  <pre><code>  year          based based_value      share share_value
  1 1956 organizational           1  org_based           2
  2 1956         action           0 ideo_based          95
  3 1956    ideological           0  act_based          95
  4 2000 organizational           0  org_based          92
  5 2000         action           0 ideo_based          87
  6 2000    ideological           0  act_based          91
  </code></pre>
  <p>or, with <code>dput</code>:</p>
  <pre><code>solution &lt;- structure(list(year = c(1956, 1956, 1956, 2000, 2000, 2000), 
      based = c(&quot;organizational&quot;, &quot;action&quot;, &quot;ideological&quot;, &quot;organizational&quot;, 
      &quot;action&quot;, &quot;ideological&quot;), based_value = c(1, 0, 0, 0, 0, 
      0), share = c(&quot;org_based&quot;, &quot;ideo_based&quot;, &quot;act_based&quot;, &quot;org_based&quot;, 
      &quot;ideo_based&quot;, &quot;act_based&quot;), share_value = c(2, 95, 95, 92, 
      87, 91)), class = &quot;data.frame&quot;, row.names = c(NA, -6L))
  </code></pre>
  <p>I thought I have to work with <code>names_pattern</code>, what I have tried is something like this, but if you try you will see, that it is not what I want:</p>
  <pre><code>pivot_longer(data=dat_plot, cols=c(&quot;share_org_based&quot;, &quot;share_ideo_based&quot;, &quot;share_act_based&quot;,
                      &quot;organizational_based&quot;, &quot;action_based&quot;, &quot;ideological_based&quot;),
               names_pattern = c(&quot;(share_[A-Za-z]+)([A-Za-z]+_based)&quot;),
               names_to = c(&quot;share&quot;, &quot;.value&quot;),
               values_to = &quot;value&quot;)
  </code></pre>
  <p>I am grateful for any leads as to how <code>names_pattern</code> works, or what am I missing.</p>