0Pricing
NLP Academy · บทเรียน

Regex ใน 5 นาที

ลิเทอรัล คลาส และตัวระบุจำนวน

Regex ใน 5 นาที เป็นบทเรียน NLP Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน NLP Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

A Tiny Language for Patterns

A regular expression is a tiny pattern language for matching text. Instead of one fixed word, you describe the shape of what you want to find.

Python Speaks Regex Too

Python uses the built-in re module for regex. Import it once and you can search, match, and extract patterns from any string.

import re
re.search("cat", "the cat sat")

Literals: Exact Characters

The simplest pattern is a literal. The pattern dog matches the exact letters d, o, g, in that order, wherever they appear in your text.

search Finds the First Match

Use re.search to scan a string and return the first place your pattern appears, or None when nothing matches at all.

m = re.search("sat", "the cat sat")
print(m.group())

Character Classes With Brackets

A character class in square brackets matches any one listed character. The pattern [abc] matches a single a, b, or c each time.

re.findall("[aeiou]", "hello")

Handy Class Shortcuts

Some classes have shortcuts. \d matches any digit, \w matches word characters, and \s matches spaces. They save you a lot of typing. 😊

The Dot Matches Anything

The dot stands for any single character except a newline. So h.t matches hat, hit, and hot, but never the two-letter ht.

Quantifiers Repeat Patterns

A quantifier says how many times the part before it repeats. Add a plus for one or more, a star for zero or more.

re.findall("a+", "aaa banana")

Exact Counts With Braces

Use braces for precise repetition. The pattern \d{3} matches exactly three digits in a row, perfect for area codes or short IDs.

re.findall("\d{3}", "call 911 now")

Anchors Pin the Position

Anchors match a position, not a character. The caret means start of string and the dollar sign means end of string.

findall Returns Every Match

While search finds one match, re.findall returns a list of every match in the text, which is great for counting or extracting many items.

re.findall("\d+", "2 cats, 5 dogs")

Quick Check

You want to match exactly three digits in a row. Which pattern fits?

Recap: Your Regex Toolkit

You met literals, classes, the dot, quantifiers, and anchors. With re.search and re.findall, you can already describe and find real patterns. 🎉

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

บทเรียน “Regex ใน 5 นาที” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “Regex ใน 5 นาที” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส NLP Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “Regex ใน 5 นาที”

ลิเทอรัล คลาส และตัวระบุจำนวน คุณปฏิบัติ NLP Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน NLP Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน NLP Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “Regex ใน 5 นาที” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน NLP Academy นี้ได้ไหม

ได้ บทเรียน NLP Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. Regex ใน 5 นาที
  2. ค้นหาอีเมลและ URL
  3. กลุ่มจับคู่และการแทนที่
  4. เคล็ดลับการสร้างโทเคนด้วย Regex
← กลับไปที่ NLP Academy