Use Regex in LibreOffice Writer to Edit Text in Batches

For advanced editing in LibreOffice Writer, open Edit > Find & Replace, expand More Options, and enable Regular expressions. Enter a pattern in Find and, if you want to change the matched text, a replacement in Replace. Use Find All or Find Next to inspect matches before choosing Replace All.

The current LibreOffice 26.8 Help describes this workflow. Regex can clean repeated spaces, locate structured text such as dates, or rearrange parts of names in one pass. The patterns below are for Writer’s Find and Replace dialog; do not assume another program uses identical syntax.

Open Find and Replace safely

Save a copy of an important document before making a large edit. This gives you a clean fallback if a pattern matches more than expected. In Writer, choose Edit > Find & Replace or press Ctrl+H on Windows and Linux, or Command+H on macOS.

  1. Click More Options to expand the dialog.
  2. Select Regular expressions. Keep it enabled for both the Find pattern and any regex-based replacement.
  3. Enter a small test pattern, then click Find Next to inspect one match or Find All to select every match.

LibreOffice treats a period (.) as any single character and an asterisk (*) as zero or more repetitions of the previous expression. Therefore, .* means zero or more characters within a paragraph. A plain asterisk is not the same as the common file-search wildcard meaning “any text.” Writer’s regular expression search is documented separately from wildcard search.

The Edit menu is open in Writer with Find & Replace highlighted above a page containing Smith, Ana and Lee, Jordan.
Open Edit and choose Find & Replace to begin a pattern-based edit in the current Writer document.

Build a pattern that matches only what you intend

Start with the smallest specific pattern that describes your target. Use anchors when the whole paragraph must match: ^ means the start of a paragraph and $ means its end. For example, ^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}$ finds a paragraph containing only a date in YYYY-MM-DD shape. It checks the shape, not whether the date is a real calendar date.

Common building blocks include \d for a decimal digit, \w for a word character, + for one or more repetitions, and square-bracket ranges such as [A-Z]. LibreOffice also documents character classes such as [[:alpha:]] and [[:digit:]]. Prefer the character class when text may include letters beyond basic English A–Z.

To clean repeated spaces, search for [ ]{2,} and replace it with one ordinary space. This pattern targets two or more literal spaces; it does not target tabs. Click Find All first to confirm that the highlighted areas are the spacing errors you mean to fix.

Reorder text with capture groups

Parentheses capture parts of a match so the replacement can reuse them. For a document containing names such as “Smith, Ana,” use this Find pattern:

([A-Za-z]+), ([A-Za-z]+)

Enter this in Replace:

$2 $1

The first group is the surname and the second is the given name, so “Smith, Ana” becomes “Ana Smith.” In LibreOffice, capture groups are written as , , and so on in the Find expression, then referenced as $1, $2, and so on in Replace. This example’s [A-Za-z] ranges cover basic English letters only; for names with accented letters, use the documented [[:alpha:]] class in both groups and inspect the results.

The expanded Find & Replace dialog in Writer shows the Regular expressions option checked.
Expand More Options and enable Regular expressions before entering a regex pattern.

Useful Writer regex patterns

TaskFindReplace
Collapse repeated spaces[ ]{2,}One space
Reorder “Surname, Given”([[:alpha:]]+), ([[:alpha:]]+)$2 $1
Reformat YYYY-MM-DD text([[:digit:]]{4})-([[:digit:]]{2})-([[:digit:]]{2})$2/$3/$1
Find an empty paragraph^$Review before replacing

The date pattern changes the visual order to MM/DD/YYYY; use it only if that format suits your readers. It does not validate dates or understand locale conventions. For empty paragraphs, use Find Next first. Deleting paragraph marks can change spacing and document structure, so do not run a broad replacement without reviewing the result.

The Find & Replace dialog shows the pattern ([A-Za-z]+), ([A-Za-z]+) and replacement $2 $1, with Smith, Ana selected in the document.
Capture groups let the replacement reuse the two parts of each matched name in a new order.

Review matches before replacing

Use Find Next to step through a few matches when a pattern is new. Use Find All to see the complete set of selected matches before replacement. If it highlights part of a word, catches unexpected punctuation, or skips accented letters, narrow or revise the pattern rather than accepting the results.

When the selection is correct, click Replace to change one match at a time or Replace All for the full document. Check the result immediately. If it is wrong, use Ctrl+Z (or the Undo command on your system) before making other edits, then adjust the pattern.

One important limit: Writer’s regex searches operate within a paragraph. The dot does not cross paragraph breaks. In the Find box, \n matches a manual line break inserted with Shift+Enter; in Writer’s Replace box, \n inserts a paragraph break. Treat that replacement carefully because it can split text into new paragraphs.

A Writer page shows the reordered names Ana Smith and Jordan Lee after replacement.
Review the changed text in context after applying a replacement.

Verify the edit

  • Scan the edited paragraphs for missing punctuation, doubled spaces, or text joined across boundaries.
  • Run the original Find pattern again. If the task was to remove a pattern, no unintended matches should remain.
  • For a transformation such as name or date reordering, compare several changed examples with the source copy before saving.

For the full syntax and edge cases, consult LibreOffice’s Writer guide to regular-expression searches, its regular-expression reference, and the Find and Replace dialog help.

Leave a Comment

Set Arabic and Hebrew Paragraphs to Right-to-Left in Writer

Set Arabic and Hebrew Paragraphs to Right-to-Left in Writer

Enable Writer’s bidirectional controls, set RTL paragraph flow, and check mixed Arabic or Hebrew text without disrupting English words and numbers.

Restore Calibri and Arial in LibreOffice Without Guesswork

Restore Calibri and Arial in LibreOffice Without Guesswork

Install metric-compatible Linux fonts or map LibreOffice fallbacks, while keeping Microsoft font licensing and layout differences in view.

Create Fillable PDFs from Forms in LibreOffice Writer

Create Fillable PDFs from Forms in LibreOffice Writer

Add usable text fields, check boxes, and drop-downs in Writer, then export a PDF recipients can complete and save.

Make LibreOffice PDFs Keep the Fonts You Used

Make LibreOffice PDFs Keep the Fonts You Used

Fix missing or substituted fonts in LibreOffice Writer PDFs, choose the right export profile, and verify which fonts are embedded before sharing.

Batch-Convert DOCX Files to PDF with LibreOffice CLI

Batch-Convert DOCX Files to PDF with LibreOffice CLI

Convert a folder of Word documents to PDF with LibreOffice commands, handle nested folders safely, and verify the output before sharing.

Make Every New Writer Document Use Your Template

Make Every New Writer Document Use Your Template

Set a custom LibreOffice Writer template as the default so new documents open with your preferred styles and page layout.

Get LibreOffice to Recognize Your Java Runtime

Get LibreOffice to Recognize Your Java Runtime

Install a compatible Java runtime, enable it in LibreOffice, and troubleshoot an empty JRE list without changing unrelated settings.

Run LibreOffice Headless in Docker for PDF Conversion

Run LibreOffice Headless in Docker for PDF Conversion

Build a small LibreOffice container, convert office documents without a GUI, and verify PDF output while limiting host-file access.

Make LibreOffice Impress Files Smaller Without Blurring Images

Make LibreOffice Impress Files Smaller Without Blurring Images

Reduce oversized LibreOffice presentation files by compressing embedded photos, choosing sensible image settings, and checking slide quality before sharing.

Stop Custom-Size Prints from Cropping in LibreOffice

Stop Custom-Size Prints from Cropping in LibreOffice

Match LibreOffice’s page dimensions to your printer, check printable margins, and correct scaling before printing a custom-size document.