<p>A tutorial I have on Regex in python explains how to use the re module in python, I wanted to grab the URL out of an A tag so knowing Regex I wrote the correct expression and tested it in my regex testing app of choice and ensured it worked. When placed into python it failed:</p>
<pre><code>result = re.match(&quot;a_regex_of_pure_awesomeness&quot;, &quot;a string containing the awesomeness&quot;)
# result is None`
</code></pre>
<p>After much head scratching I found out the issue, it automatically expects your pattern to be at the start of the string. I have found a fix but I would like to know how to change:</p>
<pre><code>regex = &quot;.*(a_regex_of_pure_awesomeness)&quot;
</code></pre>
<p>into</p>
<pre><code>regex = &quot;a_regex_of_pure_awesomeness&quot;
</code></pre>
<p>Okay, it's a standard URL regex but I wanted to avoid any potential confusion about what I wanted to get rid of and possibly pretend to be funny.</p>

[{'answer_id': 72449, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Are you using the <code>re.match()</code> or <code>re.search()</code> method? My understanding is that <code>re.match()</code> assumes a "<code>^</code>" at the beginning of your expression and will only search at the beginning of the text, while <code>re.search()</code> acts more like the Perl regular expressions and will only match the beginning of the text if you include a "<code>^</code>" at the beginning of your expression. Hope that helps.</p>\n'}, {'answer_id': 72470, 'author': 'zweiterlinde', 'author_id': 6592, 'author_profile': 'https://Stackoverflow.com/users/6592', 'pm_score': 5, 'selected': True, 'text': '<p>In Python, there\'s a distinction between "match" and "search"; match only looks for the pattern at the start of the string, and search looks for the pattern starting at any location within the string.</p>\n\n<p><a href="http://docs.python.org/lib/module-re.html" rel="noreferrer">Python regex docs</a><br>\n<a href="http://docs.python.org/lib/matching-searching.html" rel="noreferrer">Matching vs searching</a></p>\n'}, {'answer_id': 72501, 'author': 'Aaron Maenpaa', 'author_id': 2603, 'author_profile': 'https://Stackoverflow.com/users/2603', 'pm_score': 2, 'selected': False, 'text': '<pre><code>&gt;&gt;&gt; import re\n&gt;&gt;&gt; pattern = re.compile("url")\n&gt;&gt;&gt; string = "   url"\n&gt;&gt;&gt; pattern.match(string)\n&gt;&gt;&gt; pattern.search(string)\n&lt;_sre.SRE_Match object at 0xb7f7a6e8&gt;\n</code></pre>\n'}, {'answer_id': 78072, 'author': 'jfs', 'author_id': 4279, 'author_profile': 'https://Stackoverflow.com/users/4279', 'pm_score': 2, 'selected': False, 'text': "<pre><code>from BeautifulSoup import BeautifulSoup \n\nsoup = BeautifulSoup(your_html)\nfor a in soup.findAll('a', href=True):\n    # do something with `a` w/ href attribute\n    print a['href']\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/72393', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1384652/']