Pattern: Line break

“Line break” is one of the patterns that you can select on the Match panel. Use this pattern to match one line break from a set of allowed ASCII and/or Unicode line break styles, or to match a character that is not (part of) one of the selected line break styles.

This example shows how you can use the “line break” pattern to match an ASCII line break or form feed. You can find this example as “Pattern: line break” in the RegexMagic library.

  1. Click the New Formula button on the top toolbar to clear out all settings on the Samples, Match, and Action panels.
  2. On the Samples panel, click the New button to add a new sample and click the FFh button to switch the sample to hexadecimal mode. Then paste this block of bytes into the hex editor:
    41 53 43 49 49 20 63 6F  6E 74 72 6F 6C 20 63 68
    61 72 61 63 74 65 72 73 3A 00 01 02 03 04 05 06
    07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16
    17 18 19 1A 1B 1C 1D 1E 1F
  3. In the “pattern to match field” drop-down list, select “line break”.
  4. Check the CRLF pair, line feed, carriage return, and form feed options.
  5. On the Regex panel, select “Python 3.13” as your application, turn off free-spacing, and turn off mode modifiers. Click the Generate button, and you’ll get this regular expression:
    (?>\r\n|[\n\f\r])
    Unused options: Case sensitive; Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks.
  6. The Samples panel now shows that this regular expression correctly matches the line breaks we selected:
    41 53 43 49 49 20 63 6F  6E 74 72 6F 6C 20 63 68  ASCII control ch
    61 72 61 63 74 65 72 73  3A 00 01 02 03 04 05 06  aracters:␀␁␂␃␄␅␆
    07 08 09 0A 0B 0C 0D 0E  0F 10 11 12 13 14 15 16  ␇␈␉␊␋␌␍␎␏␐␑␒␓␔␕␖
    17 18 19 1A 1B 1C 1D 1E  1F                       ␗␘␙␚␛␜␝␞␟

Notice that the regular expression uses an atomic group and a separate alternative to match the CRLF pair. This ensures that when the regex encounters a CRLF it matches the CRLF as an indivisible pair.

Related Examples

Reference