how to split this type of string?
<pre><code>row_data=" 'NULL','to_date(to_char(to_date('19700101'',''YYYYMMDD') + interval '1s' * logevent_timestamp_seconds',''YYYY-MM-DD')',''YYYY-MM-DD')','NULL'"

row_data_list = row_data.split("\',\'")
</code></pre>

<p>I want to split the data accordingly into three objects</p>

<ul>
<li>NULL </li>
<li>to_date(to_char(to_date('19700101'',''YYYYMMDD') + interval '1s'* logevent_timestamp_seconds',''YYYY-MM-DD')',''YYYY-MM-DD') </li>
<li>NULL</li>
</ul>

<p>I cannot hard code it so that it can split it. Is there any way to do it, apart from hard coding and detecting it?</p>

<p>I'm reading the data row_data from a file</p>

<p>Split the string by <code>,</code>, then trim the <code>'</code> from both sides for every element:</p>

<pre><code>&gt;&gt;&gt; row_data=" 'NULL','to_date(to_char(to_date('19700101'',''YYYYMMDD') + interval '1s' * logevent_timestamp_seconds',''YYYY-MM-DD')',''YYYY-MM-DD')','NULL'"
&gt;&gt;&gt; row_data_list = list(map(lambda x: x[1:-1], row_data.strip().split(',')))
&gt;&gt;&gt; row_data_list
['NULL', "to_date(to_char(to_date('19700101'", "'YYYYMMDD') + interval '1s' * logevent_timestamp_seconds", "'YYYY-MM-DD')", "'YYYY-MM-DD')", 'NULL']
</code></pre>

<p>This will work for every string styled that way, with every number of elements.</p>

python string parsing split