Note that there are some explanatory texts on larger screens.

plurals
  1. POMatch a row with fixed columns as long as possible
    primarykey
    data
    text
    <p>I'm going to parse a position base file from a legacy system. Each column in the file has a fixed column width and each row can maximum be 80 chars long. The problem is that you don't know how long a row is. Sometime they only have filled in the first five columns, and sometimes all columns are used.</p> <p>If I KNOW that all 80 chars where used, then I simple could do like this:</p> <pre><code>^\s* (?&lt;a&gt;\w{3}) (?&lt;b&gt;[ \d]{2}) (?&lt;c&gt;[ 0-9a-fA-F]{2}) (?&lt;d&gt;.{20}) ... </code></pre> <p>But the problem with this is that if the last columns is missing, the row will not match. The last column can even be less number of chars then the maximum of that column.</p> <p>See example</p> <pre><code>Text to match a b c d "AQM45A3A text " =&gt; AQM 45 A3 "A text " //group d has 9 chars instead of 20 "AQM45F5" =&gt; AQM 45 F5 //group d is missing "AQM4" =&gt; AQM 4 //group b has 1 char instead of 2 "AQM4 ASome Text" =&gt; AQM 4 A "Some Text" //group b and c only uses one char, but fill up the gap with space "AQM4FSome Text" =&gt; No match, group b should have two numbers, but it is only one. "COM*A comment" =&gt; Comments do not match (all comments are prefixed with COM*) " " =&gt; Empty lines do not match </code></pre> <p>How should I design the Regular Expression to match this?</p> <p><strong>Edit 1</strong></p> <p>In this example, EACH row that I want to parse, is starting with AQM</p> <ul> <li>Column a is always starting at position 0 </li> <li>Column b is always starting at position 3 </li> <li>Column c is always starting at position 5 </li> <li>Column d is always starting at position 7</li> </ul> <p>If a column is not using all its space, is files up with spaces Only the last column that is used can be trimed</p> <p><strong>Edit 2</strong> To make it more clearer, I enclose here soem exemple of how the data might look like, and the definition of the columns (note that the examples I have mentioned earlier in the question was heavily simplified)</p> <p><img src="https://i.stack.imgur.com/f0366.png" alt="Example for AQM"> <img src="https://i.stack.imgur.com/Lhobn.png" alt="Definition for AQM"></p>
    singulars
    1. This table or related slice is empty.
    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