title: d3.js if else regex string match to change style
body: <p>I have the following string in a column(col2) in a csv file:</p>
  
  <pre><code>  "unserer {m}, unsere {p} and {f}, unseres {n}
  </code></pre>
  
  <p>I would like to color the background of the words preceeding {m|f|n} based on the value in { }. ( m stands for male, f for female, n for neuter )</p>
  
  <p>This, I would like to match strings and change their style and am looking for the correct syntax. I have tried filter, but was not successful to implement multiple filters</p>
  
  <pre><code>  d3.select("#sentence").html(
        if ( d.col2.match(/.*\w+\s\{f\}/) ) {
              this.style("background-color","red")
        } else {
              this.style("background-color","blue")
        };
        );
  </code></pre>
  
  <p>Thus I am looking for the correct way of writing this code.</p>
  
  <pre><code>  d3.select("#sentence").html(d.col2).filter(function () {
        if ( d.col2.match(/.*\w+\s\{f\}/) ) {
              this.style("background-color","red")
        } else {
              this.style("background-color","blue")
        };
        };);
  </code></pre>