JavaScript RegExp Form Feed Metacharacter (\f)

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

What Is \f?

\f matches the form feed control character (U+000C, ASCII 12). It once meant “next page” on printers and still shows up as a page or section break in some legacy text files.

Remember
\f  → form feed (U+000C)
\n  → newline (different character)
\r  → carriage return (different character)
\s  → any whitespace, including \f

"page1\fpage2"  → string with a form feed
/\f/.test(...)  → true when FF is present
split(/\f/)     → break on page markers
UsePrefer
Detect form feed/\f/
Split pages/sectionsstr.split(/\f/)
Any whitespace\s
Newline only\n

How to Use \f

Treat form feed as a specific control character — detect it, split on it, or replace it.

  1. Build or import text that may contain form feeds (string escape: "\f").
  2. Use /\f/ with test, match, split, or replace.
  3. Add the g flag when you need every form feed, not just the first.
  4. Do not confuse \f with \n — they are different characters.
PieceRequired?Role
\f in the patternYesMatch the form feed character
String escape "\f"For demos / fixturesInsert FF into a JavaScript string
g flagOptionalFind or replace every form feed
\sOptionalBroader whitespace class that includes \f

Pseudocode

Pseudocode
pattern has "\f"
read next character ch from the string

if ch.codePoint === 0x000C:   // form feed
    accept match
else:
    fail this path

common actions:
  test(str)      → true/false
  split(str)     → parts between FF
  replace(str)   → swap FF for space or "\n"

Cheat Sheet

Keep these facts handy when cleaning control characters.

TopicDetail
CharacterForm feed — U+000C (ASCII 12)
Regex / string/\f/ · "\f" · new RegExp("\\f")
vs newline\f ≠ \n ≠ \r
WhitespaceIncluded in \s
Split pagesdoc.split(/\f/)
Normalizestr.replace(/\f/g, "\n") or " "
StandardES3+ (universal)

Live Preview

Run common \f operations on sample text that contains a form feed.

Browser demo of the RegExp \f form feed escape — same ideas as the examples below.

Result
text = "Page A\fPage B"
/\f/.test(text)
→ true

/* form feed (U+000C) is present */

JavaScript Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Detect Form Feed

Check whether text contains a form feed — and confirm it is not a newline.

JavaScript
const withFF = "section\fnext";
const plain = "section next";

console.log(/\f/.test(withFF));  // true
console.log(/\f/.test(plain));   // false
console.log(/\n/.test(withFF));  // false
Try It Yourself

How It Works

  1. Build fixtures. "\f" inserts a real form feed into withFF; plain has only a space.
  2. Detect FF. /\f/.test(withFF) is true because U+000C is present.
  3. Miss on plain text. A normal space does not match \f.
  4. Different from newline. /\n/ fails on withFF — form feed is not \n.

Example 2 — Split Text into Sections

Break a legacy document on form feed page markers.

JavaScript
const doc = "Title\fChapter 1\fChapter 2\fIndex";

const sections = doc.split(/\f/);
console.log(sections);
// ["Title", "Chapter 1", "Chapter 2", "Index"]

console.log(sections.length); // 4
Try It Yourself

How It Works

  1. Start with markers. Three form feeds divide the string into four pieces.
  2. Split on \f. Each match becomes a cut point; the FF itself is removed.
  3. Read the parts. You get "Title", "Chapter 1", "Chapter 2", and "Index".
  4. Check length. sections.length is 4 — one entry per segment.

Example 3 — Replace Form Feeds with Newlines

Convert invisible page breaks into readable line spacing.

JavaScript
const legacy = "Page A\fPage B\fPage C";

const readable = legacy.replace(/\f/g, "\n\n");
console.log(JSON.stringify(readable));
// "Page A\n\nPage B\n\nPage C"
Try It Yourself

How It Works

  1. Use a global pattern. /\f/g finds every form feed, not only the first.
  2. Swap for newlines. Each FF becomes "\n\n" so page breaks show as blank lines.
  3. Inspect safely. JSON.stringify makes the escape sequences visible in the console.
  4. Other targets. You can also replace with a space or "" to strip page breaks.

Edge Cases & Pitfalls

Check these before relying on \f in real projects.

trap

\f is not \n

Form feed and newline are different characters. Patterns for one do not match the other.

escape

new RegExp needs double escaping

Write new RegExp("\\f"). A single "\f" string already becomes the character before the constructor sees it — for a pattern string you need "\\f".

whitespace

\s also matches form feed

Broad whitespace cleanup with /\s/g removes \f too. Use /\f/ when you mean only form feed.

display

Often invisible in the UI

Browsers may not show a visible mark for FF. Use charCodeAt, JSON.stringify, or replace with a visible marker while debugging.

Browser & Runtime Support

The \f form feed escape is core regex syntax (ES3+) and works everywhere JavaScript runs.

✓ Baseline · ES3+

RegExp \f

Supported in every modern and legacy browser, plus all Node.js versions. No polyfill required.

100% Universal support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
\f Excellent

Bottom line: Safe to use in any JavaScript environment. Focus on correctness (escaping, g flag) rather than compatibility.

Performance Notes

ApproachCostBest for
/\f/.test(str)O(n)Quick presence checks
str.split(/\f/)O(n)Page / section parsing
str.replace(/\f/g, …)O(n)Cleanup and normalization

Matching a single control character is cheap. Prefer /\f/ when you only care about form feed; use \s only when any whitespace should match.

Key Takeaways

  • Role: \f matches the form feed control character (U+000C).
  • Not a newline: use \n / \r for line endings; \f for page breaks.
  • Common jobs: test, split, and replace on legacy documents.
  • Whitespace: \s includes \f — choose the tighter pattern when you can.

One line: \f finds form feed page breaks — split or replace them when cleaning legacy text.

Frequently Asked Questions

\f matches the form feed control character (FF, Unicode U+000C, ASCII 12). It was originally used to advance to the next page on printers and still appears in some legacy text files.
No. \f is form feed (page break). \n is line feed (new line). They are different control characters, though both can act as whitespace separators in text processing.
Yes. Form feed is included in the \s whitespace class along with space, tab, newline, carriage return, and other Unicode space separators.
Use an escape in a string literal: "page1\fpage2". In a regex literal write /\f/; in new RegExp() string patterns use "\\f".
Mostly when parsing or cleaning legacy documents, printer-formatted data, or exported files that embed form feed characters as page or section breaks.
The \f escape is core regex syntax since ES3. It works in every browser and Node.js version.

Next: \n newline

Learn how the newline metacharacter matches line feed characters in JavaScript regex.

\n tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful