🛠️ToolsShed

찾기 & 바꾸기

일반 텍스트 또는 정규식 패턴으로 텍스트를 찾아 바꿉니다.

찾기 및 바꾸기 도구를 사용하면 텍스트 본문 내에서 텍스트 패턴을 검색하고 다른 것으로 바꿀 수 있습니다. 설치가 필요 없이 브라우저 내에서 모두 처리됩니다. 대부분의 텍스트 편집기에는 기본 찾기/바꾸기 기능이 있지만, 이 독립형 도구는 해당 기능이 없는 환경에서 작업하거나 특정 교체 작업을 공유하거나 문서화할 때 유용합니다.

검색어와 대체 텍스트를 입력한 다음 '모두 바꾸기'를 클릭하여 모든 일치 항목을 한 번에 대체하거나, '다음 바꾸기'를 사용하여 일치 항목을 하나씩 처리합니다. 대소문자 구분/무시, 전체 단어 일치, 정규식(regex) 모드를 지원합니다.

정규식은 정확한 텍스트보다 패턴을 따르는 콘텐츠를 찾고 바꾸는 강력한 방법입니다. 예를 들어 YYYY-MM-DD 형식의 모든 날짜를 찾아 한 번에 DD/MM/YYYY로 재형식화할 수 있습니다. 여기서 지원되는 정규식 구문은 표준 JavaScript 정규식 엔진을 따릅니다.

자주 묻는 질문

코드 구현

import re

def find_replace(text: str, find: str, replace: str,
                 use_regex: bool = False, case_sensitive: bool = True) -> str:
    """Find and replace text, with optional regex and case-insensitive modes."""
    if use_regex:
        flags = 0 if case_sensitive else re.IGNORECASE
        return re.sub(find, replace, text, flags=flags)
    else:
        if case_sensitive:
            return text.replace(find, replace)
        else:
            # Case-insensitive plain string replace
            return re.sub(re.escape(find), replace, text, flags=re.IGNORECASE)

# Examples
text = "Hello World. Hello Python."
print(find_replace(text, "Hello", "Hi"))
# Hi World. Hi Python.

print(find_replace(text, r"\bHello\b", "Greetings", use_regex=True))
# Greetings World. Greetings Python.

print(find_replace(text, "hello", "Hi", case_sensitive=False))
# Hi World. Hi Python.

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.