title: Extracting text before and after the splitting point including the splitting character in R
body: <p>I have an expression in the following format</p>
  
  <pre><code>(&lt;decimal_no&gt;&lt;space&gt;&lt;operator&gt;&lt;space&gt;&lt;decimal_no&gt;)&lt;space&gt;&lt;operator&gt;&lt;space&gt;&lt;decimal_no&gt;
  </code></pre>
  
  <p>I'm trying to split an expression (5.0 - 50.0) - 15.0 into two parts (5.0 - 50.0) and the rest of the string " - 15.0" into a list. With the following R code I'm able to split it into two parts successfully. </p>
  
  <pre><code>expr = "(5.0 - 50.0) - 15.0"
  unlist(strsplit(expr, "(?&lt;=\\))", perl = T))
  
  #output 
  "(5.0 - 50.0)" " - 15.0"
  </code></pre>
  
  <p>However when the string pattern is changed "15.0 - (5.0 - 50.0)" I want to separate the string into two elements "15.0 - " and "(5.0 - 50.0)". I can do a workaround but I want to know can this be done with a regex similar to the previous method (?&lt;=\)) ?</p>
  
  <pre><code>expr2 = "15.0 - (5.0 - 50.0)"
  unlist(strsplit(expr2, "(\\()", perl = T))
  
  #output
  "15.0 - "     "5.0 - 50.0)" #extracts the strings but the splitting character is missing
  </code></pre>
  
  <p>I think the regex (?&lt;=\)) means get all the characters before ")" including the ")". I tried using few variations (?>=\(), (\(>=?), (\(&lt;=?), (\(?\)) but nothing worked. </p>
  
  <p>Edit: Sample strings</p>
  
  <pre><code>"(5.0 - 50.0) - 15.0" -&gt; "(5.0 - 50.0)"," - 15.0" 
  "15.0 - (5.0 - 50.0)" -&gt; " - 15.0", "(5.0 - 50.0)"
  "(43.0 - 85.0) + (18.0 + 84.0)" -&gt; "(43.0 - 85.0)", " + ", "(18.0 + 84.0)"
  "((12.0 + 89.0) - 73.0) - (58.0 - 90.0)" -&gt; "(12.0 + 89.0) - 73.0) - " , "(58.0 - 90.0)"
  </code></pre>