title: regexp extract with lookbehind and lookforward with google-re2 in google data studio
body: <p>I'm trying to build a <code>REGEXP_EXTRACT</code> query inside a <code>CASE</code> statement which isn't quite working out the way I want to:</p>
  
  <p><strong>Example data:</strong></p>
  
  <pre><code>1234-ABC
  1234-abc
  1234-ABC-1a
  1234
  1234-abc-test-this
  </code></pre>
  
  <p>What I would like to to is catch the <code>ABC|abc</code> out of the query if present. If it's not present I would like to return a default value.</p>
  
  <p>I found a page where I can see the regex possibilities for <a href="https://github.com/google/re2/wiki/Syntax" rel="nofollow noreferrer">Google-RE2 RegEx</a>.</p>
  
  <p>I know how to build the case:</p>
  
  <pre><code>CASE
      WHEN REGEXP_MATCH(Eventcategory, '^([0-9])*-([a-zA-Z0-9])*$') THEN 'it matches 1234-ABC and 1234-abc'
      WHEN REGEXP_MATCH(Eventcategory, '^([0-9])*-([a-zA-Z0-9])*-([a-zA-Z0-9])*') THEN 'it matches 1234-ABC-1a and 1234-abc-test-this'
      ELSE "it matches 1234"
  END
  </code></pre>
  
  <p>The problem comes in extracting the right part of <code>Eventcategory</code>.</p>
  
  <p>What I've tried so far:</p>
  
  <pre><code>REGEXP_EXTRACT(Eventcategory, '-([a-zA-Z0-9])*-') // Then it was only still needed to remove the - at the beginning and end
  REGEXP_EXTRACT(Eventcategory, '-([a-zA-Z0-9])*$') // if it was 1234-Abc
  REGEXP_EXTRACT(Eventcategory, '(?=^([0-9])*-)((-[a-zA-Z])*)')
  REGEXP_EXTRACT(Eventcategory, '((-[a-zA-Z])*)')
  REGEXP_EXTRACT(Eventcategory, '(?=^([0-9])*-)((-[a-zA-Z])*)')
  REGEXP_EXTRACT(Eventcategory, '(-([a-zA-Z])+)')
  REGEXP_EXTRACT(Eventcategory, '(?=(^([0-9])*-))(-([a-zA-Z])+)')
  </code></pre>
  
  <p>Really hope someone can help me out since I don't have any options left at the moment.</p>