e9cbf23ab5
이전 재구성 작업에서 Dev/ 폴더가 누락되었던 것을 반영. - Dev/Topic_Programming(중첩 폴더, 78개)은 Dev 자체 최상위 폴더들 (Architecture/Conventions/Engineering_Intelligence 등)과 완전 중복이라 제거. - Dev 최상위 엔지니어링 지식 폴더(Architecture/Conventions/Engineering_Intelligence/ Failure_Library/Generalized_Principles/Language/Pattern_Catalog/Platform_Guides/ Subsystems, 77개)는 이미 Topic_Programming/Topic_Programming에 더 최신 버전이 존재해 중복 제거(고유 콘텐츠 1개는 예외 처리하여 이동 보존). - Dev의 W3Schools 언어 튜토리얼 폴더(Topic_C/CPP/CSS/CSharp/HOWTO/HTML/Java/ JavaScript/PHP/Python/SQL/W3CSS, 1201개)는 전부 Topic_Programming 하위로 이동. - 에이전트 운영 상태(.astra/docs)는 그대로 유지, 콘텐츠 폴더만 정리. - Topic_Programming 최종 문서 수: 2784 → 3985.
4.1 KiB
4.1 KiB
id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
| id | title | category | status | verification_status | canonical_id | aliases | duplicate_of | source_trust_level | confidence_score | created_at | updated_at | review_reason | merge_history | tags | raw_sources | applied_in | github_commit | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| php-regex-functions | PHP RegEx Functions | Programming_Language | draft | conceptual |
|
B | 0.9 | 2026-07-04 | 2026-07-04 |
|
|
PHP RegEx Functions
🎯 한 줄 통찰 (One-line insight)
preg_match() and preg_match_all() return fundamentally different numbers for the same match — preg_match() caps at 1 (match found) or 0 (not found), while preg_match_all() returns the actual COUNT of matches, meaning preg_match() can never tell you "how many," only "whether." [S1]
🧠 핵심 개념 (Core concepts)
preg_match($pattern, $str)— returns 1 if found, 0 if not. [S1]preg_match_all($pattern, $str)— returns the total NUMBER of matches. [S1]preg_replace($pattern, $replacement, $str)— replaces all matches with a new string. [S1]preg_split($pattern, $str)— splits a string into an array using regex matches as separators. [S1]preg_grep($pattern, $array)— filters an array, keeping only elements matching the pattern; third argumentPREG_GREP_INVERTflips this to keep NON-matching elements. [S1]- Grouping with
( )— applies quantifiers to a whole sub-pattern, and captures sub-matches. [S1]
📖 세부 내용 (Details)
- preg_match:
$str = "Visit W3Schools"; $pattern = "/w3schools/i"; echo preg_match($pattern, $str); // 1. [S1] - preg_match_all (count):
$str = "The rain in SPAIN falls mainly on the plains."; $pattern = "/ain/i"; echo preg_match_all($pattern, $str); // counts occurrences. [S1] - preg_replace:
$str = "Visit Microsoft!"; $pattern = "/microsoft/i"; echo preg_replace($pattern, "W3Schools", $str);. [S1] - preg_split:
$str = "This is a text"; $pattern = "/[\s:]/"; $components = preg_split($pattern, $str); print_r($components);. [S1] - preg_grep (filter matching):
$input = ["Red", "Pink", "Green", "Blue", "Purple"]; $result = preg_grep("/^p/i", $input); // Pink, Purple. [S1] - preg_grep inverted (filter non-matching):
$result = preg_grep("/^p/i", $input, PREG_GREP_INVERT); // Red, Green, Blue. [S1] - Grouping:
$str = "Apples and bananas."; $pattern = "/ba(na){2}/i"; echo preg_match($pattern, $str); // matches "banana" pattern: ba + (na)x2. [S1]
⚖️ 모순 및 업데이트 (Contradictions & updates)
- preg_match와 preg_match_all의 반환값 차이: 전자는 0/1(존재 여부)만 반환하지만 후자는 실제 매치 개수를 반환한다는 점이 핵심 구분점이다. [S1]
🛠️ 적용 사례 (Applied in summary)
현재 발견된 실제 적용 사례가 없습니다 — preg_grep()으로 배열에서 특정 패턴에 맞는 항목만 필터링하는 것이 실전 데이터 필터링의 대표 사례다. [S1]
💻 코드 패턴 (Code patterns)
Filtering an array with preg_grep() (PHP):
$input = ["Red", "Pink", "Green", "Blue", "Purple"];
$result = preg_grep("/^p/i", $input); // items starting with "p" (case-insensitive)
print_r($result); // Pink, Purple
✅ 검증 상태 및 신뢰도
- 상태: draft
- 검증 단계: conceptual
- 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
- 신뢰 점수: 0.90
- 중복 검사 결과: 신규 생성 (New discovery)
🔗 지식 그래프 (Knowledge Graph)
- 상위/루트: PHP Tutorial
- 관련 개념: PHP RegEx, PHP Forms, PHP Form Validation
- 참조 맥락: 정규표현식 함수 활용 — 폼(Forms) 섹션으로 이어짐.
📚 출처 (Sources)
- [S1] W3Schools — PHP Regular Expression Functions — https://www.w3schools.com/php/php_regex_functions.asp
📝 변경 이력 (Change history)
- 2026-07-04: Initial draft synthesized from the W3Schools "PHP Regular Expression Functions" page (Astra wiki-curation, P-Reinforce v3.1 format).