> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.adnabu.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Nabu 重定向管理器支持哪些重定向的正则表达式语法？

### Nabu 重定向管理器支持 JavaScript 风格的正则表达式（RegEx），用于在您的 Shopify 商店中设置高级重定向。

#### 支持的 RegEx 语法

以下是应用程序中支持的主要 RegEx 功能：

1. 锚点

  ^ → 匹配 URL 路径的开始。
  $ → 匹配 URL 路径的结束。

| **示例**: ^/products/.*$
| 匹配任何以 /products/ 开头的 URL。

2. 字符类

  . → 匹配任何单个字符。
  [abc] → 匹配括号内的任意一个字符。
  [0-9] → 匹配 0–9 之间的任意数字。
  [^abc] → 匹配除 a、b 或 c 之外的任何字符。

| **示例**: ^/products/[0-9]+$
| 匹配 /products/123, /products/456 等。

3. 量词

  (*) → 匹配 0 或更多次重复。
  (+) → 匹配 1 或更多次重复。
  ? → 匹配 0 或 1 次重复。
  {n} → 精确匹配 n 次。
  {n,} → 匹配 n 次或更多次。
  {n,m} → 匹配 n 到 m 次。

| **示例**:  ^/products/[a-z]{3,5}$
| 匹配具有 3 到 5 个字母的产品句柄（例如，/products/bag, /products/shoes）。

4. 分组和交替

 ( ) → 定义一个捕获组。
 | → 在模式之间作为 OR 工作。

| **示例**: ^/(products|collections)/(.*)$
| 匹配 /products/... 和 /collections/....

5. 捕获组

 (pattern) → 捕获匹配的一部分。
 $1, $2, … $5 → 在目标链接中重用捕获的值。
 Nabu 支持最多 5 个捕获组。

| 来源路径: ^/products/(.*)/(.*)$
| 目标链接: /new-products/$1/$2
| /products/men/shoes → /new-products/men/shoes。

### Shopify 示例

* 将所有产品重定向到一个集合：

| 来源路径: ^/products/.*$
| 目标链接: /collections/all-products

* 将产品 ID（仅数字）重定向到新集合

| 来源路径: ^/products/[0-9]+$
| 目标链接: /collections/special-deals

* 使用捕获组重定向

| 来源路径: ^/products/(.*)$
| 目标链接: /collections/$1
| /products/shirt → /collections/shirt。

* 同时重定向产品和集合

| 来源路径: ^/(products|collections)/(.*)$
| 目标链接: /archived/$1/$2
| /products/hat → /archived/products/hat。