title: How can I pass a variable in the optional part of a Python Behave regex expression?
body: <p>I have a Behave test step that contains an optional time component.</p>
  <p>This is the test step without the optional component:</p>
  <pre><code>Scenario: A user can create, validate, and delete a full session (DELETE /full/:user_id)
    When I create a session with userID 6ac0d2a2-3fa0-41bb-ba3d-ffdcf95f73f2 and companyID 9ca7ef6e-790e-4f7d-8b6c-1179c49294ec
  </code></pre>
  <p>This is the test step with the optional component:</p>
  <pre><code>Scenario: A user cannot validate an existing but expired full session (GET / )
    When I create a session with userID 6ac0d2a2-3fa0-41bb-ba3d-ffdcf95f73f2 and companyID 9ca7ef6e-790e-4f7d-8b6c-1179c49294ec and set the expiration time to 1 second
  </code></pre>
  <p>This is the corresponding function:</p>
  <pre><code>@when('I create a session with userID (?P&lt;user_id&gt;.*) and companyID (?P&lt;company_id&gt;.*)(?: and set the expiration time to (?P&lt;seconds&gt;\d+) second)?')
  def send_request(context, user_id, company_id, seconds):
      url = context.session_url + &quot;/full&quot;
      body = {
          &quot;userId&quot;: user_id,
          &quot;companyId&quot;: company_id
      }
  
      print(seconds)
      # if specifying the expiration time instead of using the defaults:
      if seconds:
          body[&quot;maxAge&quot;] = &quot;PT1S&quot;
          body[&quot;maxIdle&quot;] = &quot;PT1S&quot;
  </code></pre>
  <p>When I run the test step with the optional parameter, the <code>seconds</code> variable is not passed into the function and evaluates as <code>None</code>. How can I change the regex to pass in the number specified in the Gherkin .feature file?</p>