title: Why the regex I write doesn't work properly?
body: <pre class="lang-py prettyprint-override"><code>pattern = '(ns:m\.[^ ]+ )|(ns:g\.[^ ]+ )'
  query = "PREFIX ns: &lt;http://rdf.freebase.com/ns/&gt;\nSELECT DISTINCT ?x\nWHERE {\nFILTER (?x != ns:m.0pz91)\nFILTER (!isLiteral(?x) OR lang(?x) = '' OR langMatches(lang(?x), 'en'))\nns:m.0pz91 ns:film.producer.film ?x .\n?x ns:film.film.genre ?c .\n?c ns:film.film_genre.films_in_this_genre ns:g.11b5lzm6b0 . \n}"
  entities = re.findall(pattern, query)
  </code></pre>
  
  <p>What I am trying to do is to find all freebase entities in my query, i.e.,<code>'ns:g.11b5lzm6b0'</code> and <code>'ns:m.0pz91'</code> in my example. However, the code I wrote returns <code>[('ns:m.0pz91)\nFILTER ', ''), ('ns:m.0pz91 ', ''), ('', 'ns:g.11b5lzm6b0 ')]</code> instead of <code>['ns:m.0pz91 ', 'ns:g.11b5lzm6b0 ']</code>. <br> I solved the problem by using 2 separate regex, i.e., <code>ns:m\.[^ ]+</code> and <code>ns:g\.[^ ]+</code>, however, I still don't understand why I can't directly use <code>(ns:m\.[^ ]+ )|(ns:g\.[^ ]+ )</code> to match <code>ns:m\.[^ ]+</code> or <code>ns:g\.[^ ]+</code>.</p>