---
title: extractDomain – ฟังก์ชันดึงชื่อโดเมน
url: https://www.thepexcel.com/functions/n8n/string-functions/extract-domain-n8n/
type: function-explainer
program: n8n
syntax: extractDomain(url)
date: 2025-12-16
updated: 2025-12-17
scores:
  popularity: 6
  difficulty: 3
  usefulness: 6
---

# extractDomain – ฟังก์ชันดึงชื่อโดเมน

> ดึงชื่อโดเมนจาก URL หรือ email

## คำอธิบาย

extractDomain ดึงชื่อโดเมนจาก URL หรือ email ฟังก์ชันนี้มีประโยชน์ในการวิเคราะห์ URL แยกแหล่งข้อมูล หรือจัดหมวดหมู่ข้อมูลตามโดเมน

## Syntax

```excel
extractDomain(url)
```

**Variant**

```excel
$json.website.extractDomain()
```

ใช้เป็น method เมื่อ $json.website มี URL

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| url | Yes | string |  | URL หรือ email address (เช่น 'https://example.com/page' หรือ 'user@example.com') |

## เคสการใช้งาน

### วิเคราะห์ URL จาก Analytics

ดึงชื่อโดเมนจาก referrer URLs เพื่อวิเคราะห์แหล่งการเยี่ยมชม

_เหมาะกับ:_ url-analysis

### จัดหมวดหมู่ Email ตามโดเมน

ดึงชื่อโดเมนจาก email addresses เพื่อจัดหมวดหมู่อีเมลตามบริษัท

_เหมาะกับ:_ email-categorization

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: ดึงโดเมนจาก URL

```excel
{{ extractDomain('https://www.example.com/page/content') }}
```

**ผลลัพธ์:** `example.com`

ฟังก์ชันดึงชื่อโดเมน 'example.com' จาก URL ที่มีเส้นทางต่างๆ

### 2. ตัวอย่างที่ 2: ดึงโดเมนจาก Email

```excel
{{ extractDomain('john.doe@company.com') }}
```

**ผลลัพธ์:** `company.com`

สูตรนี้ดึกชื่อโดเมน 'company.com' จาก email address

### 3. ตัวอย่างที่ 3: วิเคราะห์ Referrer URLs

```excel
{{ $json.referrers.map(r => r.extractDomain()) }}
```

**ผลลัพธ์:** `[example.com, google.com, facebook.com, ...]`

ดึงชื่อโดเมนจากทุก referrer URL เพื่อวิเคราะห์แหล่งการเยี่ยมชม

## หมายเหตุเพิ่มเติม

⚠️ ฟังก์ชัน extractDomain() ใช้ร่วมกับ extractEmail() และ extractUrl() เพื่อแยกส่วนต่างๆ ของข้อมูล URL และ email เมื่อข้อมูล input ไม่ใช่ URL หรือ email ที่ถูกต้อง ผลลัพธ์อาจไม่คาดหวัง

## คำถามที่พบบ่อย

**Q: extractDomain() จะลบ www prefix หรือไม่?**

ใช่ extractDomain() ลบ www prefix ออก ดังนั้น 'www.example.com' และ 'example.com' ให้ผลลัพธ์เดียวกัน

**Q: extractDomain() จะรับ subdomain ได้หรือ?**

ได้ แต่จะแยกเฉพาะชื่อโดเมนหลัก เช่น 'sub.example.com' ให้ผลลัพธ์ 'example.com'

**Q: ใช้ extractDomain() เมื่อไหร่ในการทำงาน?**

ใช้เมื่อต้องการวิเคราะห์ URL, จัดหมวดหมู่ email, หรือแยกชื่อโดเมนสำหรับการจัดกลุ่มข้อมูล

## ฟังก์ชันที่เกี่ยวข้อง

- [extractEmail – ฟังก์ชันดึงอีเมลจากข้อความ](https://www.thepexcel.com/functions/n8n/string-functions/extract-email-n8n/)
- [extractUrl – ฟังก์ชันดึง URL จากข้อความ](https://www.thepexcel.com/functions/n8n/string-functions/extract-url-n8n/)
- [isDomain – ฟังก์ชันตรวจสอบว่าเป็นโดเมนหรือไม่](https://www.thepexcel.com/functions/n8n/string-functions/is-domain-n8n/)
- [map – แปลงแต่ละรายการในอาร์เรย์ (transform elements)](https://www.thepexcel.com/functions/n8n/array-functions/map-n8n/)

## แหล่งข้อมูลเพิ่มเติม

- [n8n Expressions: extractDomain](https://docs.n8n.io/code/expressions/) _(documentation)_
- [URL Parsing Functions](https://docs.n8n.io/code/builtin/overview/) _(guide)_

---

_Source: [https://www.thepexcel.com/functions/n8n/string-functions/extract-domain-n8n/](https://www.thepexcel.com/functions/n8n/string-functions/extract-domain-n8n/)_
