Based on my SO question, but more specifically:
Find a RegEx such that, given a text where paragraphs end with an empty line (or $
at the very end), match the up to twenty last characters of a paragraph excluding the \r
or $
but no more than three complete "words" including the "separators" in between and the punctuation following it. The following constraints apply:
- "words" also include abbreviations and the like (and thus punctuation), i.e. "i.e." and "non-trivial" count as one word each
- whitespaces are "separators"
- isolated dashes do not count as "words" but as "separators"
- "separators" before the first word must not be included
- trailing punctuation counts to that limit, but not the leading one nor the linebreaks and
$
that must not be in the matching group - whether trailing punctuation is included in the match or not is up to you
Some examples:
The early bird catches the worm. Two words.
But only if they got up - in time.
Here we have a supercalifragilisticexpialidocious etc. sentence.
Short words.
Try accessing the .html now, please.
Vielen Dank und viele Grüße.
Did any-one try this?
Score is given in bytesteps: bytes multiplied by amount of steps according to https://regex101.com, but there are three penalties:
- if the upper limit of words cannot trivially+ be modified: +10%
- if the upper limit of character count cannot trivially+ be modified: +10%
- failure to handle unicode used in actual words: add the percentage of world population speaking the language according to Wikipedia the failing word stems from. Example: Failing to match the German word "Grüße" as a word => +1.39%. Whether you consider a language's letters as single characters or count the bytes to utf8-encode them is up to you. The penalty does not have to be applied before someone actually provides a counter-example, so feel free to demote your competitors ;)
Since this is my first challenge, please suggest any clarifications. I assume regular-expression means there are no "loopholes" to exclude.
+ With trivially modified I mean expressions such as {0,2}
and {21}
are valid but repeating something three times (which would have to be re-repeated to increase the amount words) is not.
3
and20
should appear as numbers in a single place which can be changed? \$\endgroup\$\s\s+
ever match the paragraph? \$\endgroup\$