title: Identifying white space in a twig variable
body: <p>I have a situation where I need to identify if there is a blank space in a variable in a twig template, and to treat it slightly differently.</p>
  
  <p>Given names in this application are stored with middle initials in the given name field; they are not stored separately.</p>
  
  <p>What I'm trying to achieve is this: Typically most given names are one word, e.g. "John" or "Susan" or something similar.   In some of these cases we have cases where the middle initial is stored within this variable (e.g.  John J) </p>
  
  <p>Following standard citation standards, we need to be able to list items like this:</p>
  
  <pre><code>{{ surname }}, {{ given_name }}, ed.
  </code></pre>
  
  <p>This way it would appear like "Smith, John, ed."   This is normally fine, however in some situations, where there is a middle initial, it appears as "Smith, John J, ed."  - this is incorrect.   I can't add a period after the given name, as "Smith, John., ed" would be an incorrect citation standard.</p>
  
  <p>What I'm trying to do is to identify if a <code>given_name</code> contains a space, followed by a single letter, and then format it differently. </p>
  
  <p>Something like this:</p>
  
  <pre><code>{% if given_name [has a blank space preceding a single letter] %}
  {{ given_name }}., ed.
  {% else %}
  {{ given_name }}, ed.
  {% endif %}
  </code></pre>
  
  <p>Is there a way to do this with regex within twig, or is there another method?</p>
  
  <p>Thanks in advance</p>