<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>

Are you using the
```
re.match()
```
or
```
re.search()
```
method? My understanding is that
```
re.match()
```
assumes a "
```
^
```
" at the beginning of your expression and will only search at the beginning of the text, while
```
re.search()
```
acts more like the Perl regular expressions and will only match the beginning of the text if you include a "
```
^
```
" at the beginning of your expression. Hope that helps.