Template:Nowordbreak: Difference between revisions

From DynamicPageList3 Manual
Content added Content deleted
(Created page with "<includeonly>{{#vardefine:n|{{{2|{{{length|0}}}}}}}}<!-- -->{{#vardefine:text|{{{1|{{{text|}}}}}}}}<!-- -->{{#vardefine:sub|{{#sub:{{#var:text}}|0|{{#var:n}} }} }}<!-- -->{{#v...")
 
mNo edit summary
Line 21: Line 21:
| <code><nowiki>{{nowordbreak|Testing, testing, 123|20}}</nowiki></code>
| <code><nowiki>{{nowordbreak|Testing, testing, 123|20}}</nowiki></code>
| {{nowordbreak|Testing, testing, 123|20}}
| {{nowordbreak|Testing, testing, 123|20}}
|}
|}</noinclude>

[[Category:Templates]]
</noinclude>

Revision as of 22:39, 18 July 2019

This template will return the first n characters of a string, without breaking words. Numbers however, will be broken apart.

Note: This template requires the RegexFunctions Extension.

Usage examples

Code Gives
{{nowordbreak|Testing, testing, 123|11}} 11}}{{#vardefine:text|Testing, testing, 123}}{{#vardefine:sub|{{#sub:{{#var:text}}|0|{{#var:n}} }} }}{{#vardefine:n+|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:sub+|{{#sub:{{#var:text}}|0|{{#var:n+}} }} }}{{#rmatch:{{#var:sub}}|/[\W0-9]$/|{{#var:sub}}|{{#rmatch:{{#var:sub+}}|/[\W0-9]$/|{{#var:sub}}|{{#rmatch:{{#var:sub}}|/^(.*[\s]).*$/|$1|{{#var:sub}}}}}}}}
{{nowordbreak|Testing, testing, 123|20}} 20}}{{#vardefine:text|Testing, testing, 123}}{{#vardefine:sub|{{#sub:{{#var:text}}|0|{{#var:n}} }} }}{{#vardefine:n+|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:sub+|{{#sub:{{#var:text}}|0|{{#var:n+}} }} }}{{#rmatch:{{#var:sub}}|/[\W0-9]$/|{{#var:sub}}|{{#rmatch:{{#var:sub+}}|/[\W0-9]$/|{{#var:sub}}|{{#rmatch:{{#var:sub}}|/^(.*[\s]).*$/|$1|{{#var:sub}}}}}}}}