Note that there are some explanatory texts on larger screens.

plurals
  1. POsplit string with regex using a release character and separators
    primarykey
    data
    text
    <p>I need to parse an EDI file, where the separators are <code>+</code>, <code>:</code> and <code>'</code> signs and the escape <em>(release)</em> character is <code>?</code>. You first split into segments </p> <pre><code>var data = "NAD+UC+ABC2378::92++XYZ Corp.:Tel ?: ?+90 555 555 11 11:Mobile1?: ?+90 555 555 22 22:Mobile2?: ?+90 555 555 41 71+Duzce+Seferihisar / IZMIR++35460+TR" var segments = data.Split('\''); </code></pre> <p>then each segment is split into segment data elements by <code>+</code>, then segment data elements are split into component data elements via <code>:</code>.</p> <pre><code>var dataElements = segments[0].Split('+'); </code></pre> <p>the above sample string is not parsed correctly because of the use of release character. I have special code dealing with this, but I am thinking that this should be all doable using </p> <pre><code>Regex.Split(data, separator); </code></pre> <p>I am not familiar with Regex'es and could not find a way to do this so far. The best I came up so far is </p> <pre><code>string[] lines = Regex.Split(data, @"[^?]\+"); </code></pre> <p>which omits the character before <code>+</code> sign.</p> <pre><code>NA U ABC2378::9 +XYZ Corp.:Tel ?: ?+90 555 555 11 11:Mobile1?: ?+90 555 555 22 22:Mobile2?: ?+90 555 555 41 7 Duzc Seferihisar / IZMI +3546 TR </code></pre> <p>Correct Result Should be:</p> <pre><code>NAD UC ABC2378::92 XYZ Corp.:Tel ?: ?+90 555 555 11 11:Mobile1?: ?+90 555 555 22 22:Mobile2?: ?+90 555 555 41 7 Duzce Seferihisar / IZMIR 35460 TR </code></pre> <p>So the question is this doable with Regex.Split, and what should the regex separator look like.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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