Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This was quick-tested in Perl.</p> <p><strong>Edit</strong> - This regex code simulates the word wrap used (good or bad) in MS-Windows <em>Notepad.exe</em> </p> <pre><code> # MS-Windows "Notepad.exe Word Wrap" simulation # ( N = 16 ) # ============================ # Find: @"(?:((?&gt;.{1,16}(?:(?&lt;=[^\S\r\n])[^\S\r\n]?|(?=\r?\n)|$|[^\S\r\n]))|.{1,16})(?:\r?\n)?|(?:\r?\n|$))" # Replace: @"$1\r\n" # Flags: Global # Note - Through trial and error discovery, it apparears Notepad accepts an extra whitespace # (possibly in the N+1 position) to help alignment. This matters not because thier viewport hides it. # There is no trimming of any whitespace, so the wrapped buffer could be reconstituted by inserting/detecting a # wrap point code which is different than a linebreak. # This regex works on un-wrapped source, but could probably be adjusted to produce/work on wrapped buffer text. # To reconstitute the source all that is needed is to remove the wrap code which is probably just an extra "\r". (?: # -- Words/Characters ( # (1 start) (?&gt; # Atomic Group - Match words with valid breaks .{1,16} # 1-N characters # Followed by one of 4 prioritized, non-linebreak whitespace (?: # break types: (?&lt;= [^\S\r\n] ) # 1. - Behind a non-linebreak whitespace [^\S\r\n]? # ( optionally accept an extra non-linebreak whitespace ) | (?= \r? \n ) # 2. - Ahead a linebreak | $ # 3. - EOS | [^\S\r\n] # 4. - Accept an extra non-linebreak whitespace ) ) # End atomic group | .{1,16} # No valid word breaks, just break on the N'th character ) # (1 end) (?: \r? \n )? # Optional linebreak after Words/Characters | # -- Or, Linebreak (?: \r? \n | $ ) # Stand alone linebreak or at EOS ) </code></pre> <p><strong>Test Case</strong> The wrap width N is 16. Output matches Notepad's and over a variety of widths. </p> <pre><code> $/ = undef; $string1 = &lt;DATA&gt;; $string1 =~ s/(?:((?&gt;.{1,16}(?:(?&lt;=[^\S\r\n])[^\S\r\n]?|(?=\r?\n)|$|[^\S\r\n]))|.{1,16})(?:\r?\n)?|(?:\r?\n|$))/$1\r\n/g; print $string1; __DATA__ hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh bbbbbbbbbbbbbbbbEDIT FOR CLARITY - I know there are ways to do this in multiple steps, or using LINQ or vanilla C# string manipulation. The reason I am using a single regex call, is because I wanted practice. with complex regex patterns. - END EDIT pppppppppppppppppppUf </code></pre> <p>Output >></p> <pre><code> hhhhhhhhhhhhhhhh hhhhhhhhhhhhhhh bbbbbbbbbbbbbbbb EDIT FOR CLARITY - I know there are ways to do this in multiple steps, or using LINQ or vanilla C# string manipulation. The reason I am using a single regex call, is because I wanted practice. with complex regex patterns. - END EDIT pppppppppppppppp pppUf </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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