Small SEO Tools

How to Rearrange Date Text with Regex Capture Groups

A plain-text event list may store dates as 2026-10-23 while its publishing template calls for 23/10/2026. Replacing each number separately is easy to get wrong. A regular expression can capture the three parts and insert them in a different order.

This workflow uses the Find and Replace Text tool on a small, controlled sample. It rearranges text shaped like a year, month and day. It does not check whether a date exists, infer its intended locale, or change a time zone.

Start with dates whose meaning you already know

Keep an untouched copy of the source. Confirm that its order is year-month-day and that the destination explicitly expects day/month/year. A value such as 2027-01-09 becomes 09/01/2027; that output needs an agreed format because readers can interpret slash-separated dates differently.

Paste this example into Your text:

Event date: 2026-10-23
Backup date: 2027-01-09
Keep ID: A2026-10-23B

The first two values are intended dates. The last line is an identifier and should remain unchanged. Real source material needs the same distinction: a date-shaped substring is not automatically a date field.

Capture the parts and rearrange them

Enable Use regular expression. Leave Whole word only off because the pattern below includes its own boundaries. Keep Replace all on. Match case can stay off; this pattern contains no letters.

Enter this directly in Find, using single backslashes and no surrounding slashes or flags:

\b(\d{4})-(\d{2})-(\d{2})\b

Set Replace with to:

$3/$2/$1

The parentheses capture four digits, then two digits, then two digits. Their positions make the year group 1, month group 2 and day group 3. MDN explains this numbering in its capturing group reference.

The replacement requests day, slash, month, slash, year. It preserves the captured leading zeroes rather than converting the parts into numbers. Numbered replacement tokens are documented in MDN’s string replacement reference; the site’s tool supports the three tokens used here.

Check the output and replacement count

Press Replace. For this sample, expect two replacements and:

Event date: 23/10/2026
Backup date: 09/01/2027
Keep ID: A2026-10-23B

If you turn Replace all off, only the first matching value changes across the entire input. It does not mean one replacement on each line.

Understand what this pattern will miss or change

The \b assertions require a word boundary at each end. They keep the sample’s letter-connected ID intact. As MDN’s word boundary reference explains, these boundaries concern word characters, including letters, digits and underscore; they do not understand document fields.

A hyphenated ID such as record-2026-10-23-copy can still contain a match. Do not apply this pattern blindly to code, URLs, filenames, mixed identifiers or a whole database export. Extract only the date values you intend to edit, or use a field-aware process for structured data.

Two-digit widths also matter. 2026-1-9 will not match. Conversely, 2026-99-88 matches the shape and becomes 88/99/2026, even though it is not a valid calendar date. Check ranges, month lengths and leap years separately when validity matters.

Review before using the converted list

  1. Compare the replacement count with the intended number of date values.
  2. Check a converted date with a leading zero, a value that should remain unchanged, and any surrounding punctuation.
  3. Use the Text Compare tool to inspect the original and edited versions. Our draft comparison guide provides a separate review workflow.
  4. Copy the reviewed output into the destination and confirm that its date format is stated clearly.

If the job is an ordinary word correction, our whole-word replacement guide covers simpler matching options. Use this capture-group pattern when the task specifically requires rearranging known date text.