• 회원가입
  • 로그인
  • 구글아이디로 로그인

[web] PHP 정규표현식(=정규식) (chatGPT AI 답변)

1,607  

PHP 정규표현식 (chatGPT AI 답변)

[한국어]

 

PHP 정규식(regex)은 검색 패턴을 정의하는 일련의 문자입니다. 패턴은 문자열을 일치(때로는 교체)하거나 문자열에 지정된 패턴이 포함되어 있는지 확인하는 데 사용됩니다.


PHP에서는 preg_* 함수를 사용하여 정규식으로 작업할 수 있습니다. 일반적으로 사용되는 일부 기능은 다음과 같습니다.

  • preg_match: 패턴과 문자열이 일치하는지 검색합니다.
  • preg_match_all: 패턴과 문자열 사이의 모든 일치 항목을 검색합니다.
  • preg_replace: 문자열에서 패턴의 모든 항목을 교체로 바꿉니다.
  • preg_split: 지정된 패턴으로 문자열을 분할합니다.

 

Regex 패턴은 일반적으로 슬래시(/)와 같은 두 개의 구분 기호 사이에 작성/됩니다. 예를 들어 패턴 /^[a-z]+$/은 소문자만 포함하고 문자로 시작하고 끝나는 모든 문자열과 일치합니다.

 

Regex 패턴에는 특별한 의미가 있는 다양한 특수문자와 메타문자 포함됨.

  • . (마침표): 줄바꿈 제외한 모든 단일문자와 일치
  • * (아스테리크): 0개 이상의 선행 문자 발생과 일치
  • ^ (꺽쇠): 줄의 시작과 일치

 

정규식은 강력한 도구이지만 복잡하고 읽고 유지 관리하기 어려울 수 있음을 기억하는 것이 중요합니다. 이들을 최대한 활용하려면 구문과 사용법을 확실하게 이해하는 것이 좋습니다.

 


[영어]

 

PHP Regular Expression (regex) is a sequence of characters that define a search pattern. The pattern is used to match (and sometimes replace) strings, or to check if a string contains the specified pattern.


In PHP, you can use the preg_* functions to work with regular expressions. Some of the commonly used functions include:

  • preg_match: searches for a match between a pattern and a string
  • preg_match_all: searches for all matches between a pattern and a string
  • preg_replace: replaces all occurrences of a pattern in a string with a replacement
  • preg_split: splits a string by a specified pattern

 

Regex patterns are written between two delimiters, usually slashes (/). For example, the pattern /^[a-z]+$/ matches any string that contains only lowercase letters, and starts and ends with a letter.


Regex patterns can include various special characters and meta-characters that have special meanings, such as

  • . (matches any single character except a newline),
  • * (matches zero or more occurrences of the preceding character), 
  • ^ (matches the start of a line).

 

It's important to remember that regular expressions are a powerful tool, but they can also be complex and difficult to read and maintain. To get the most out of them, it's helpful to have a solid understanding of their syntax and usage.

 



분류 제목
web 웹 미래 - (앱 만들 필요 없어짐 / 비밀번호 없어짐)
web AJAX 읽는 법
web HTML CSS JavaScript jQuery PHP SQL BootStrap 코딩언어 역할 쉬운 설명
web ChatGPT 이용해 프로그램 제작 방법/절차/노하우
web PHP 버전별 주요이슈/새문법 (chatGPT AI 답변)
web 사이트 커뮤니티 활성화시키는 방법 (chatGPT AI 답변)
web (다음/카카오) 외부 스크립트 사용 홈페이지 로딩 지연 에러 해결
web ASGI 서버 개념
web 공공API 사용법 가이드 (chatGPT AI 답변)
web 코딩 (제작의뢰/수주) 시, 반드시 (APM/빌더)버전 공유하기
web 체에디터 (cheditor) gif 움짤 이미지 에러 해결책 (= animated gif image erro…
web 무료호스팅 사이트 모음
web 사용자 입력값 받아 표시하기 시스템 이해하기
web 파이썬(Python) 모드나 키보드인터럽트(KeyboardInterrupt) 모드에서 빠져나오기
web Dart (다트) 앱 코딩언어 소개 / Flutter (플러터) / Adroid Studio (안드로이드 스…
web Apache log4j 취약점 대응 가이드
web 리눅스 보안 업그레이드만 진행하기
web (utf-8 / euc-kr) 차이점 - 문자셋 인코딩 방식 종류
web CSS 핵심 3대장/삼대장 (찾기 → 수정 → 반영) = 찾아서 수정 후 변경사항 적용하기
web (웹호스팅/가상호스팅) 이용 중 속도 느릴 때 체크할 사항
2/19
목록
찾아주셔서 감사합니다. Since 2012