정규 표현식 마스터하기(Regex)
고급 패턴 일치에 활용되는 정규 표현식의 구문과 강력한 기능을 이해합니다.
정규 표현식 마스터하기(Regex)은(는) CoddyKit의 무료 Linux Command Line Mastery 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Linux Command Line Mastery 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Linux Command Line Mastery 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Intro to Regular Expressions
Welcome to Regular Expressions (Regex)! Regex is a powerful mini-language used for pattern matching in text. It's like a super-charged search tool.
You can use Regex to search, replace, and validate specific text patterns in files or command output. Mastering it will make you much more efficient at the command line!
Matching Exact Text
The simplest Regex matches literal characters. This means the pattern will look for the exact sequence of characters you provide.
For example, searching for apple will only find occurrences of "apple".
echo "I have an apple and a pineapple." | grep 'apple'Any Single Character: The Dot (.)
The dot (.) is a special character, called a "metacharacter". It matches any single character, except for a newline. Use it when you don't care what character is in a specific spot.
echo "cat, cot, cut, c@t" | grep 'c.t'Matching Repetition: Quantifiers
Quantifiers let you specify how many times a character or group should appear. These are powerful for flexible matching:
*: Matches zero or more occurrences.+: Matches one or more occurrences.?: Matches zero or one occurrence (makes it optional).
echo "color colour coor" | grep 'colou*r'Specific Choices: Character Classes
Use square brackets ([]) to match any one character from a specified set. This defines specific options for a single position in your pattern.
For example, [aeiou] would match any single vowel.
echo "grey gray" | grep 'gr[ae]y'Defining Ranges in Classes
Inside character classes, you can specify ranges of characters using a hyphen (-). This makes your patterns much shorter and easier to read.
[0-9]: Matches any digit.[a-z]: Matches any lowercase letter.[A-Z]: Matches any uppercase letter.[a-zA-Z]: Matches any letter (case-insensitive).
echo "num1 num2 numA" | grep 'num[0-9]'Excluding Characters: Negation
To match any character that is NOT in a specified set, place a caret (^) as the first character inside the square brackets ([^...]).
echo "apple, banana, 123, !@#" | grep '[^a-z]'Start and End: Anchors
Anchors don't match characters; they match positions. They "anchor" your pattern to the start or end of a line.
^: Matches the beginning of a line.$: Matches the end of a line.
Note: When ^ is used outside of [], it's an anchor, not a negation!
echo -e "start here\n here end\nstart and end" | grep '^start'Putting It All Together
Let's combine some of these concepts. Imagine you want to find lines that start with a capital letter, followed by any number of lowercase letters, and end with a digit.
echo -e "Hello1\nworld2\nAnotherTest3" | grep '^[A-Z][a-z]*[0-9]$'Regex Challenge
Consider the following text:
apple
apples
apply
app
AppleWhich regular expression would match "apple" and "apples", but NOT "apply", "app", or "Apple"?
Recap: Regex Fundamentals
In this lesson, you've taken your first steps into the powerful world of Regular Expressions! We covered:
- Literal matching for exact text.
- The
.metacharacter for any single character. - Quantifiers (
*,+,?) for repetition. - Character classes (
[]) and ranges ([a-z]) for specific sets. - Negation (
[^]) to exclude characters. - Anchors (
^,$) for start and end of lines.
These are the building blocks for creating sophisticated text patterns. Keep practicing!
자주 묻는 질문
“정규 표현식 마스터하기(Regex)” 강의는 무료인가요?
네 — “정규 표현식 마스터하기(Regex)” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Linux Command Line Mastery 강의 전체를 잠금 해제할 수 있습니다. Linux Command Line Mastery 강의에는 총 4개의 강의가 포함되어 있습니다.
“정규 표현식 마스터하기(Regex)”에서 뭘 배우나요?
고급 패턴 일치에 활용되는 정규 표현식의 구문과 강력한 기능을 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 Linux Command Line Mastery을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Linux Command Line Mastery을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Linux Command Line Mastery은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.
“정규 표현식 마스터하기(Regex)” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Linux Command Line Mastery 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Linux Command Line Mastery 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 정규 표현식 마스터하기(Regex)
- 고급 `grep` 및 `find` 패턴
- 명령 연결을 위한 `xargs`
- sed와 tr로 대규모 스트림 편집하기