This document contains the content of /resources/docs/text/regex_line_wrapping.txt. Download the file by setting the ?act=download parameter, or access the raw file at either srcs.cc or src.cerium.cc.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Wraps plain text and HTML to 80 character lines (by default).
# Output string will always end with a newline.
# Uses the format:
# /pattern/flags, 'substitution'
# Wraps lines.
/(.{1,80})(?: |$)/gm, '$1\n'
# Wraps lines, matches multiple spaces as breaks.
/(.{1,80})(?:(?<! ) +|$)/gm, '$1\n'
# Wraps lines, matches multiple spaces as breaks, any existing newlines become double-newlines.
/(.{1,80})(?:(?<! ) +|$(?:\n*(?=\n)|\n*))/gm, '$1\n'
# Wraps lines including HTML entities.
/((?:[^&\n]|&[^;]*;){1,80})(?: |$)/gm, '$1\n'
# Wraps lines including HTML tags.
/((?:[^<>\n]|(?:<[^>]*>)+[^<>\n]){1,80})(?: |$|(?<! )(?=<))/gm, '$1\n'
# Wraps lines including HTML entities and tags.
/((?:[^&<>\n]|&[^;]*;|(?:<[^>]*>)+(?:[^&<>\n]|&[^;]*;)){1,80})(?: |$|(?<! )(?=<))/gm, '$1\n'
# Wraps lines including HTML entities and tags, matches multiple spaces as breaks.
/((?:[^&<>\n]|&[^;]*;|(?:<[^>]*>)+(?:[^&<>\n]|&[^;]*;)){1,80})(?:(?<! ) +|$|(?<! )(?=<))/gm, '$1\n'
# Wraps lines including HTML entities and tags, matches multiple spaces as breaks, any existing newlines become double-newlines.
/((?:[^&<>\n]|&[^;]*;|(?:<[^>]*>)+(?:[^&<>\n]|&[^;]*;)){1,80})(?:(?<! ) +|$(?:\n*(?=\n)|\n*)|(?<! )(?=<))/gm, '$1\n'
|| | | | | | | | || || | | | | | ||
|| | Char | |Entit| | Tag | | Next char || || |Spaces| | Newlines | |Tag openi||
|| +------+ +-----+ |---------+ +------------------|| || +------+ +----------------+ +---------+|
|| | Tags || || Line breaks non-capturing group |
|| +------------------------------+| |+-----------------------------------------+
|| Single characters non-capturing group | |
|+---------------------------------------------------+ |
| Line capturing group |
+-----------------------------------------------------------+
More resources