0Pricing
NLP Academy · レッスン

5 分でわかる正規表現

リテラル、文字クラス、量指定子

「5 分でわかる正規表現」はCoddyKit上の無料NLP Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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. 🎉

よくある質問

「5 分でわかる正規表現」レッスンは無料ですか?

はい。「5 分でわかる正規表現」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、NLP Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 NLP Academyコースには全4レッスンが含まれています。

「5 分でわかる正規表現」で何を学びますか?

リテラル、文字クラス、量指定子 ブラウザで直接実行するハンズオンコードでNLP Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

NLP Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのNLP Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「5 分でわかる正規表現」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このNLP Academyレッスンでコードを書いて実行できますか?

はい。すべてのNLP Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 5 分でわかる正規表現
  2. メールアドレスと URL を見つける
  3. キャプチャグループと置換
  4. 正規表現によるトークン化のテクニック
← NLP Academyに戻る