title: Python Regex, optional word in brackets?
body: <p>I have a quick question on regex, I have a certain string to match. It is shown below:</p>
  <pre><code>&quot;[someword] This Is My Name 2010&quot;
  or
  &quot;This Is My Name 2010&quot;
  or
  &quot;(someword) This Is My Name 2010&quot;
  </code></pre>
  <p>Basically if given any of the strings above, I want to only keep &quot;This Is My Name&quot; and &quot;2010&quot;.</p>
  <p>What I have now, which I will use result = re.search and then result.group() to get the answer:</p>
  <pre><code>'[\]\)]? (.+) ([0-9]{4})\D'
  </code></pre>
  <p>Basically it works with the first and third case, by allowing me to optionally match the end bracket, have a space character, and then match &quot;This Is My Name&quot;.</p>
  <p>However, with the second case, it only matches &quot;Is My Name&quot;. I think this is because of the space between the '?' and '(.+)'.</p>
  <p>Is there a way to deal with this issue in pure regex?</p>
  <p>One way I can think of is to add an &quot;if&quot; statement to determine if the word starts with a [ or ( before using the appropriate regex.</p>