Note that there are some explanatory texts on larger screens.

plurals
  1. POSplit a string based on each time a Deterministic Finite Automata reaches a final state?
    text
    copied!<p>I have a problem which has an solution that can be solved by iteration, but I'm wondering if there's a more elegant solution using regular expressions and <code>split()</code></p> <p>I have a string (which excel is putting on the clipboard), which is, in essence, comma delimited. The caveat is that when the cell values contain a comma, the whole cell is surrounded with quotation marks (presumably to escape the commas within that string). An example string is as follows:</p> <pre><code>123,12,"12,345",834,54,"1,111","98,273","1,923,002",23,"1,243" </code></pre> <p>Now, I want to elegantly split this string into individual cells, but the catch is I cannot use a normal split expression with comma as a delimiter, because it will divide cells that contain a comma in their value. Another way of looking at this problem, is that I can <strong>ONLY</strong> split on a comma if there is an <strong>EVEN</strong> number of quotation marks preceding the comma.</p> <p>This is easy to solve with a loop, but I'm wondering if there's a regular expression.split function capable of capturing this logic. In an attempt to solve this problem, I constructed the Deterministic Finite Automata (DFA) for the logic.</p> <p><img src="https://i.stack.imgur.com/Y210D.png" alt="alt text"></p> <p>The question now is reduced to the following: is there a way to split this string such that a new array element (corresponding to /s) is produced each time the final state (state 4 here) is reached in a DFA?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload