title: Data Studio Regex (Google RE2) to Extract Subdirectory from Path
body: <p>I'm working with a Google Data Studio field that has a page URL Path contained within it. Examples:</p>
  <ul>
  <li><strong>/</strong></li>
  <li><strong>/sample-url</strong></li>
  <li><strong>/sample-url-2</strong>/</li>
  <li><strong>/#sample-url-5</strong>/</li>
  <li><strong>/sample-url-3</strong>/sample-url-4</li>
  <li><strong>/sample-url-3</strong>/sample-url-6</li>
  </ul>
  <p>In each one, I want to be capturing the bold portion in a custom formula/field--from the first slash, up to but excluding the second slash if there is one, and also including the first slash if that's the whole path. (In essence, the first subdirectory.) I would be open to recording the second backslash when there is one if that would make the solution simpler, but I'm guessing it's more complicated that way. I tried the following:</p>
  <pre><code>REGEXP_EXTRACT(Field, &quot;^/[^/]+/$&quot;)
  </code></pre>
  <p>But it didn't work; everything returned null. What is wrong with that string?</p>