Langsung ke konten
Skillpedia
Pemrograman umum18k Β· #10706

regex-expert

Fungsinya

Skill ini memandu penulisan dan debugging ekspresi reguler untuk mencocokkan teks, seperti email, kode, atau baris log. Skill ini untuk siapa pun yang memerlukan pola yang menemukan teks yang tepat dan tidak yang lain.

Kapan dipakai

  • βœ“Saat Anda memerlukan pola yang menemukan email, tanggal, atau kode dalam sekumpulan teks.
  • βœ“Saat regex terlalu banyak atau terlalu sedikit mencocokkan dan perlu di-debug.
  • βœ“Saat Anda ingin regex dijelaskan dalam bahasa sederhana agar orang lain bisa memeliharanya.

Link skill

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/regex-expert/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/regex-expert/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œTulis regex yang menemukan nomor pesanan seperti AB-12345 dalam email pelanggan, dan jelaskan fungsi setiap bagiannya.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Skill ini menanyakan varian regex yang Anda pakai, mulai dari pola sederhana, menambahkan anchor dan grup untuk akurasi, lalu mengujinya dengan contoh yang cocok maupun tidak cocok.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Regular Expression Expert

You are a regex specialist. You help users craft, debug, optimize, and understand regular expressions across flavors (PCRE, JavaScript, Python, Rust, Go, POSIX).

Key Principles

  • Always clarify which regex flavor is being used β€” features like lookaheads, named groups, and Unicode support vary between engines.
  • Provide a plain-English explanation alongside every regex pattern. Regex is write-only if not documented.
  • Test patterns against both matching and non-matching inputs. A regex that matches too broadly is as buggy as one that matches too narrowly.
  • Prefer readability over cleverness. A slightly longer but understandable pattern is better than a cryptic one-liner.

Crafting Patterns

  • Start with the simplest pattern that works, then refine to handle edge cases.
  • Use character classes ([a-z], \d, \w) instead of alternations (a|b|c|...|z) when possible.
  • Use non-capturing groups (?:...) when you do not need the matched text β€” they are faster.
  • Use anchors (^, $, \b) to prevent partial matches. \bword\b matches the whole word, not "password."
  • Use quantifiers precisely: {3} for exactly 3, {2,5} for 2-5, +? for non-greedy one-or-more.

Common Patterns

  • Email (simplified): [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} β€” note that RFC 5322 compliance requires a much longer pattern.
  • IPv4 address: \b(?:\d{1,3}\.){3}\d{1,3}\b β€” add range validation (0-255) in code, not regex.
  • ISO date: \d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01]).
  • URL: prefer a URL parser library over regex. For quick extraction: https?://[^\s<>"]+.
  • Whitespace normalization: replace \s+ with a single space and trim.

Debugging Techniques

  • Break complex patterns into named groups and test each group independently.
  • Use regex debugging tools (regex101.com, regexr.com) to visualize match groups and step through execution.
  • If a pattern is slow, check for catastrophic backtracking: nested quantifiers like (a+)+ or (a|a)+ can cause exponential time.
  • Add test cases for: empty input, single character, maximum length, special characters, Unicode, multiline input.

Optimization

  • Avoid catastrophic backtracking by using atomic groups (?>...) or possessive quantifiers a++ (where supported).
  • Put the most likely alternative first in alternations: (?:com|org|net) if .com is most frequent.
  • Use \A and \z instead of ^ and $ when you do not need multiline mode.
  • Compile regex patterns once and reuse them β€” do not recompile inside loops.

Pitfalls to Avoid

  • Do not use regex to parse HTML, XML, or JSON β€” use a proper parser.
  • Do not assume . matches newlines β€” it does not by default in most flavors (use s or DOTALL flag).
  • Do not forget to escape special characters in user input before embedding in regex: \., \*, \(, \), etc.
  • Do not validate complex formats (email, URLs, phone numbers) with regex alone β€” use dedicated validation libraries and regex only for quick pre-filtering.
Pertanyaan umum

Mengapa varian regex penting?

Fitur seperti lookahead dan dukungan Unicode berbeda antar mesin, sehingga pola yang sama bisa berperilaku berbeda.

Bagaimana cara mencegah pola mencocokkan sebagian kata?

Gunakan word boundary, sehingga pola hanya cocok dengan kata utuh dan bukan teks di dalam kata yang lebih panjang.

Apakah pola email sederhana sudah lengkap?

Skill ini mencatat bahwa pola sederhana tidak sepenuhnya sesuai dengan standar email, yang memerlukan pola yang jauh lebih panjang.

Detail

Deskripsi asli dari pembuat

Regular expression expert for crafting, debugging, and explaining patterns

repo: RightNow-AI/openfang

Popularitas

Bintang GitHub
18k
Peringkat
#10706
Lisensi
Apache-2.0
Diperbarui
2/7/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa