# Advanced Renamer regular expression reference

This reference describes the modified regular expressions engine bundled with Advanced Renamer 4.29, including the application's replacement handling. It applies to regex-enabled renaming methods. The Script method uses JavaScript's own regular expression engine and replacement syntax.

## Enable regex and choose the input

Set `"regularexpressions": true` on a method that supports it. See the [method reference](format-reference.md) for the applicable fields. Regex syntax has no effect in fields that do not support regular expressions.

Replace searches the current name produced by preceding methods. `"applyto": "name"` searches the basename and preserves the extension; `"extension"` searches the extension alone, and `"nameandextension"` searches the complete filename. For example, `^report$` matches `report.txt` with `applyto: "name"`, but does not match the complete filename.

An unanchored pattern searches within that input. Use `^` and `$` to require a whole-name match. Replace's `occurrence: 0` replaces every non-overlapping match; a positive integer replaces only that occurrence, counting from 1. If no match exists, the name is unchanged. List Replace replaces all matches for each row and applies its rows sequentially.

## Pattern syntax

Some constructs supported by the engine are restricted in fields that also parse tags; see [Tags and regex](#tags-and-regex-in-the-same-method).

The expressions in this table are the text entered into the application's pattern field, before JSON escaping.

| Pattern | Meaning |
| --- | --- |
| `report` | Literal text, found anywhere unless anchored. |
| `.` | One Unicode code point. |
| `\.` | A literal dot. Escape regex punctuation when matching it literally. |
| `[abc]`, `[a-z]`, `[^abc]` | One listed character, one character in a range, or one outside the class. |
| `\d`, `\D` | An ASCII digit `0`–`9`, or a character outside that set. |
| `\w`, `\W` | A Unicode letter, mark, number, or underscore; or a character outside that set. |
| `\s`, `\S` | A whitespace character, or a non-whitespace character. |
| `\b`, `\B` | A word boundary, or a position that is not a word boundary, using Unicode word characters. |
| `^`, `$` | Start and end of the selected filename portion. |
| `a*`, `a+`, `a?` | Zero or more, one or more, or zero or one occurrence of `a`. |
| `a{3}`, `a{3,}`, `a{3,5}` | Exactly three, at least three, or three to five occurrences. |
| `.*?`, `.+?`, `a{3,5}?` | Lazy repetition: try the shortest match first. Repetition is greedy by default. |
| `a++`, `a*+`, `a{3,5}+` | Possessive repetition: do not give matched characters back during backtracking. |
| `cat\|dog` | Alternation: either branch. Group alternatives when adding surrounding text. |
| `(pattern)` | Capturing group, numbered by opening parenthesis from 1. |
| `(?:pattern)` | Group without capturing or changing capture numbering. |
| `(?<part>pattern)` | Named capturing group, usable as `${part}` in replacement text. |
| `\1` | In a search pattern, match the same text captured by group 1. |
| `(?=pattern)`, `(?!pattern)` | Positive or negative lookahead; test following text without consuming it. |
| `(?<=pattern)`, `(?<!pattern)` | Engine-supported positive or negative lookbehind; rejected in Replace/List Replace by tag validation. |
| `(?>pattern)` | Engine-supported atomic group; rejected in Replace/List Replace by tag validation. |

Capture references in a pattern use `\1`; `$1` is replacement syntax.

## Case and inline modifiers

Replace and List Replace use `casesensitive: false` for case-insensitive matching and `true` for case-sensitive matching. This affects matching, not the case of captured text returned by substitutions.

| Inline modifier | Effect |
| --- | --- |
| `(?i)`, `(?-i)` | Enable or disable case-insensitive matching from this point. |
| `(?x)`, `(?-x)` | Enable or disable extended syntax, which ignores pattern whitespace and permits `#` comments outside character classes. |
| `(?i:pattern)` | Apply a modifier within this group only. |

For example, `(?-i)^IMG_\d+$` requires uppercase `IMG_`, even when the method otherwise ignores case. Inline `(?i)` means ignore case; it is unrelated to the `\U` replacement case conversion described below. Regex patterns are plain expressions without JavaScript-style `/.../flags` delimiters.

## Unicode support and limits

Patterns operate on Unicode code points, including accented letters and supplementary characters such as emoji. A combining accent counts as a separate code point; the engine does not automatically normalize composed and decomposed spellings.

Use Unicode general categories for more precise matching:

| Pattern | Meaning |
| --- | --- |
| `\p{L}`, `\pL` | Any Unicode letter. |
| `\p{Lu}`, `\p{Ll}`, `\p{Lt}`, `\p{Lm}`, `\p{Lo}` | Uppercase, lowercase, titlecase, modifier, or other letter. |
| `\p{M}` | Combining mark; subcategories are `Mn`, `Mc`, and `Me`. |
| `\p{N}` | Number; subcategories are `Nd`, `Nl`, and `No`. |
| `\p{Nd}` | Decimal digit, including non-ASCII digits. |
| `\p{P}`, `\p{S}`, `\p{Z}`, `\p{C}` | Punctuation, symbol, separator, or other character. |
| `\P{L}` | Any character outside the letter category. |
| `[\p{L}\p{M}]` | A letter or combining mark. |

For names containing combining accents, `\p{L}[\p{L}\p{M}]*` requires an initial letter and allows subsequent letters and marks. Add spaces, apostrophes, or hyphens explicitly if the naming rule allows them. `\w` also permits numbers and underscores.

Only short general-category codes and their supported two-letter subcategories are accepted. Names such as `\p{Letter}` and script/block names such as `\p{Latin}` are not supported. `\x{...}` escapes are limited to U+FFFF; enter supplementary characters literally. Supplementary character ranges and supplementary case folding are not supported. Case conversion uses single-character mappings, so do not expect expansions such as `ß` to `SS`.

## Replacement text and captures

Replace and List Replace support the following substitutions. These are replacement expressions, before JSON escaping; they do not describe search-pattern syntax.

| Replacement | Result |
| --- | --- |
| `$1`, `\1` | Text captured by numbered group 1. The application converts `\1` to `$1` before substitution. |
| `${1}` | Explicitly delimited group number. `${1}0` means group 1 followed by literal `0`; `$10` means group 10. |
| `${part}` | Text captured by the named group `(?<part>...)`. |
| `$0`, `$&` | The entire regex match. |
| `\L$1`, `\L\1` | Lowercase the text captured by group 1. |
| `\U$1`, `\U\1` | Uppercase the text captured by group 1. |
| `\l$1`, `\u$1` | Lowercase or uppercase only the first character of group 1. |
| `$` | A literal dollar sign. `$$` produces two dollar signs, not one. |

**Bare `\L1` and `\U1` are not capture substitutions.** They produce the literal digit `1`. Include `$1` or `\1` after the case-conversion marker.

Case conversion applies to the following capture and then resets. For example, `\U$1-$2` uppercases group 1 while preserving group 2's case. Repeat the marker to convert another capture: `\U$1-\U$2`. A literal character immediately after a marker consumes that conversion, so keep the marker adjacent to the capture. `\E` is not a supported end-of-conversion marker.

Captured text retains its original case even when matching ignores case. An optional group that did not participate contributes an empty string. Text outside the matched region is retained. An empty replacement deletes the matched text.

## Tags and regex in the same method

Replace and List Replace expand Advanced Renamer tags in search and replacement fields before regex processing. For example, `<Title>` is a metadata tag, while `$1` is a regex capture substitution. Tag expansion and regex escaping are separate steps: a metadata value inserted into a search pattern can itself contain regex punctuation.

Prefer numbered backreferences such as `\1` inside search patterns; angle-bracket forms such as `\k<part>` can be interpreted as tags by the application's tag parser. To match literal angle brackets, use regex escapes `\x3C` and `\x3E` rather than tag-like text.

## JSON escaping

Double every regex or replacement backslash when writing a JSON string. Dollar signs need no JSON escaping. The application's text fields use the expression in the middle column; `.aren` files use the JSON string in the right column.

| Purpose | Expression | JSON string |
| --- | --- | --- |
| One or more ASCII digits | `\d+` | `"\\d+"` |
| A literal dot | `\.` | `"\\."` |
| Unicode letters | `\p{L}+` | `"\\p{L}+"` |
| Repeated captured text in a pattern | `^(\w+)_\1$` | `"^(\\w+)_\\1$"` |
| Group 1 in replacement | `$1` | `"$1"` |
| Group 1, alternate replacement syntax | `\1` | `"\\1"` |
| Lowercase group 1 | `\L$1` | `"\\L$1"` |
| Lowercase group 1, alternate syntax | `\L\1` | `"\\L\\1"` |
| Uppercase group 1 | `\U$1` | `"\\U$1"` |
| Uppercase group 1, alternate syntax | `\U\1` | `"\\U\\1"` |
| Named capture in replacement | `${part}` | `"${part}"` |
| Match a literal backslash | `\\` | `"\\\\"` |
| A literal double quote | `"` | `"\""` |

A JSON string such as `"\1"` or `"\U1"` is invalid JSON. The same text inside a programming-language string may need another escaping layer; do not copy that extra layer into the `.aren` file. A Windows path such as `C:\Photos\Output` uses `"C:\\Photos\\Output"`.

## Worked examples

For a date rearrangement, this method changes `2026-11-06_report.txt` to `06-11-2026_report.txt`:

```json
{
  "methodname": "replace",
  "active": true,
  "applyto": "name",
  "replace": "^(\\d{4})-(\\d{2})-(\\d{2})_(.+)$",
  "replacewith": "$3-$2-$1_$4",
  "casesensitive": false,
  "regularexpressions": true,
  "occurrence": 0
}
```

This is a method object to put in `methods`, not a complete project. Complete projects with expected results are available for [backslash capture substitutions](examples.md#34-rearrange-captures-with-backslash-substitutions), [capture case conversion](examples.md#35-change-the-case-of-regex-captures), [named captures](examples.md#36-rearrange-named-regex-captures), and [lookahead](examples.md#37-replace-numbers-before-a-suffix-with-lookahead).
