REGEXREPLACE in ONLYOFFICE: Replace Patterns and Select Occurrences
Replace regex matches in ONLYOFFICE with occurrence selection, case options and a tested capture-replacement difference in Desktop 10.0.0.169.
Verification status: Five specified replacement cases were checked in ONLYOFFICE Desktop Editors Community 10.0.0.169 on Linux. The guide distinguishes selected-occurrence behavior from replace-all behavior; other examples are independently checked references. How formula examples are checked
Quick answer: =REGEXREPLACE("A12B34","[0-9]+","X") returns AXBX. By default, every matching digit run is replaced. An occurrence argument can target a match counted from the beginning or the end.
Important desktop behavior: In Desktop Editors Community 10.0.0.169, capture references such as $1 expanded when replacing all matches, but were inserted literally when replacing one selected occurrence. The worked comparison below makes that difference visible.
Availability and version history
- Introduced: Official Desktop Editors and Docs histories add REGEXREPLACE in 9.3.0, dated February 25, 2026.
- Availability: Currently catalogued and tested in Desktop Editors Community 10.0.0.169 on Linux. No retirement endpoint is established.
- Scope: Its individual help destination was unavailable. Syntax is backed by official function-specific source; native observations do not establish parity across web, mobile or other builds.
- Checked: October 14, 2026, using official sources, independent string models and the five native replacement cases identified below.
Syntax and occurrence selection
=REGEXREPLACE(text, pattern, replacement, [occurrence], [case_sensitivity])
The pinned official implementation of REGEXREPLACE defines the first three arguments as text. Supply quoted literals or references to cells containing those values.
| Argument | Purpose |
|---|---|
| text | Original text to rewrite |
| pattern | Regular expression defining the matches, without surrounding / / delimiters |
| replacement | Text to insert instead of each selected match |
| occurrence | 0 replaces all matches, the default. Positive integers count from the start; negative integers count from the end |
| case_sensitivity | 0 is case-sensitive, the default; 1 is case-insensitive |
Use integer occurrence values. Occurrence 2 means the second matching substring, not the second character of the original text. The inspected implementation returns the original text when there is no match or the requested occurrence is outside the match count.
Reproduce the basic replacement choices
Put A12B34 in A2, [0-9]+ in B2 and X in C2, without enclosing quote characters. Use D1:E1 for Occurrence and Result; enter 0, 1, 2 and -1 in D2:D5.
In E2 enter =REGEXREPLACE($A$2,$B$2,$C$2,D2) and fill through E5:
| Row | Occurrence | Expected E |
|---|---|---|
| 2 | 0 | AXBX |
| 3 | 1 | AXB34 |
| 4 | 2 | A12BX |
| 5 | -1 | A12BX |
The dollar signs keep the three input references fixed as the occurrence reference changes. The default formula with the fourth argument omitted, and literal formulas using occurrences 2 and -1, were tested natively and produced AXBX, A12BX and A12BX respectively. The occurrence-1 X result is independently checked against the same source logic.
A negative occurrence counts from the end of the match list, without reversing the output text. Here the last match is 34, so 2 and -1 select the same substring.
Captures: all matches and a selected match differ
These two formulas were recalculated in Desktop Editors Community 10.0.0.169:
| Formula | Native result |
|---|---|
=REGEXREPLACE("A12B34","([0-9]+)","[$1]",0) |
A[12]B[34] |
=REGEXREPLACE("A12B34","([0-9]+)","[$1]",1) |
A[$1]B34 |
The parentheses create capture group 1. For the all-match case, $1 in the replacement string becomes the captured digits. For the selected-occurrence case, the same characters remain literal.
The inspected official source explains the difference: all-match replacement supplies a replacement string to the regex engine, while selected-match replacement returns the requested text from a callback. Do not assume a capture-based rewrite will preserve its meaning when you change occurrence from 0 to 1 or -1. Use a plain literal replacement for selected occurrences unless you have separately checked the intended behavior.
This finding is specific to the tested build and inspected source, not a promise that every later release will retain the same distinction.
Advanced example: standardize a reference label
On a separate blank worksheet, set A1:C1 to Original, Standardized, and Changed?. Enter these text inputs in A2:A4:
| Row | A: Original | Expected B |
|---|---|---|
| 2 | AB-204 / XY-007 | AB:204 / XY:007 |
| 3 | DE-018 | DE:018 |
| 4 | No reference | No reference |
In B2 enter:
=REGEXREPLACE(A2,"([A-Z]{2})-([0-9]{3})","$1:$2",0)
Fill through B4. This independent example uses the all-match capture path: the first captured field stays before the colon and the second stays after it. The fixed widths reduce accidental matches, but the pattern still searches for matching substrings rather than validating the complete input.
In C2 enter =B2<>A2 and fill through C4. Expect TRUE, TRUE, FALSE. The unchanged result in row 4 is expected because no substring matches; it is not evidence that the input contains a valid reference.
Keep the original column. A rewrite can discard separators or distinctions that another system expects, even when the formula produces exactly the requested text.
Case-sensitive cleanup
In a separate empty block, type Ref: A12 ref: B34 in A8. The independently checked results are:
| Formula | Expected result |
|---|---|
=REGEXREPLACE(A8,"ref:","ID:",0,0) |
Ref: A12 ID: B34 |
=REGEXREPLACE(A8,"ref:","ID:",0,1) |
ID: A12 ID: B34 |
The fourth argument remains 0 because the fifth argument controls case sensitivity. Leaving out the occurrence position would change which argument receives the value.
For literal text replacement without regex rules, compare SUBSTITUTE. For replacement by character position and length, compare REPLACE. Choose the operation that describes your data rather than forcing every edit into a pattern.
Errors and limits
An invalid pattern is not the same as no match. Check quotation marks, parentheses and brackets before hiding an error with a wrapper. The inspected implementation uses JavaScript regular expressions; do not assume another spreadsheet’s entire regex dialect is interchangeable.
Replacement text can have special meaning in the all-match path, as $1 demonstrates. If you intend to insert dollar signs or other regex replacement tokens literally, test that exact replacement rather than treating the capture example as a general escaping recipe.
English examples use commas between arguments. Local formula separators and punctuation inside quoted patterns serve different purposes. Preserve the pattern text when adapting a formula to your settings.
For matching text without changing it, see REGEXEXTRACT. For a Boolean match check, see REGEXTEST. Neither a successful regex nor a rewritten label proves that a record is valid, unique or safe to share.