Is regex the best way to extract data from log
<p>I've got a file full of log and I'm trying to extract some data from those log, a log look like:</p>

<pre><code>IP_adress - - [Date_time] "method" response_nb time "page" "UA" "IP_adress"
</code></pre>

<p>I want to extract the IP_adress and UA.
Is using a regex a good idea to extract data from those log or is there some other way to do it properly?</p>

<p>Just split the string and get last two elements.</p>

<pre><code>&gt;&gt;&gt;
&gt;&gt;&gt; str = 'IP_adress - - [Date_time] "method" response_nb time "page" "UA" "IP_a
dress"'
&gt;&gt;&gt; tmp_list = str.split()
&gt;&gt;&gt;
&gt;&gt;&gt; tmp_list
['IP_adress', '-', '-', '[Date_time]', '"method"', 'response_nb', 'time', '"page
"', '"UA"', '"IP_adress"']
&gt;&gt;&gt; tmp_list[-1]
'"IP_adress"'
&gt;&gt;&gt; tmp_list[-2]
'"UA"'
&gt;&gt;&gt;
</code></pre>

<p>If first IP Adress is required...</p>

<pre><code>&gt;&gt;&gt; tmp_list[0]
'IP_adress'
&gt;&gt;&gt;
</code></pre>

<p>Replace double quotes as below from last IP Adress.</p>

<pre><code>&gt;&gt;&gt;
&gt;&gt;&gt; tmp_list[-1].replace('"','')
'IP_adress'
&gt;&gt;&gt;
</code></pre>

python regex python-2.7