> ## 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 Redirect Manager 支援哪些重定向的正則表達式語法?

### Nabu Redirect Manager 支援 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。