Regex get content between two pipes AND return a space where two pipes are next to each other with no spaces <p>How can I get all content between pipes and return a space where it comes across two pipes next to each other? </p> <p>An example string and desired output is:</p> <pre><code>|test1| test2|test3 || test 4 | Result1: "test1" Result2: "test2" Result3: "test3" Result4: " " Result5: "test4" </code></pre> <p>The closest I've got so far is: </p> <ul> <li><code>/[^\|]+)/</code> which will get all data between pipes but does not detect <code>||</code>.</li> <li><code>/\|([^\|]*)/</code> which will get all data between pipes and detect <code>||</code> but have an extra whitespace result at the end.</li> </ul>