~/devtools / regex / url
tool::regex-guide

regex url

/^https?:\/\/[^\s\/$.?#].[^\s]*$/i

URL 주소 검증

ad · 728×90
정규식 패턴
/^https?:\/\/[^\s\/$.?#].[^\s]*$/i
플래그:i
패턴 분석
^https?http or https scheme
:\/\/Literal ://
[^\s\/$.?#]First domain char: not whitespace, slash, dot, $, ?, #
.Any single character
[^\s]*Rest of URL: any non-whitespace characters
$End of string
매칭 예시
https://example.com
http://sub.domain.org/path?q=1
https://api.site.io/v1/users
비매칭 예시
ftp://file.server.com
example.com
https://
//no-scheme.com

http 또는 https 프로토콜로 시작하는 URL을 검증하는 패턴입니다. 도메인, 경로, 쿼리스트링 등 일반적인 URL 구성 요소를 허용합니다. ftp나 mailto 같은 다른 스킴은 별도 패턴이 필요합니다.

언어별 사용법

JavaScriptRegExp 객체 또는 리터럴 사용
const pattern = /^https?:\/\/[^\s\/$.?#].[^\s]*$/i;

// Test a string
console.log(pattern.test("https://example.com")); // true
console.log(pattern.test("ftp://file.server.com")); // false

// Match and extract
const result = "https://example.com".match(pattern);
Pythonre 모듈 사용
import re

pattern = r"^https?:\/\/[^\s\/$.?#].[^\s]*$"
flags = re.IGNORECASE

# Test a string
if re.fullmatch(pattern, "https://example.com", flags):
    print("Valid")

# Find all matches in text
matches = re.findall(pattern, text, flags)
Javajava.util.regex 패키지 사용
import java.util.regex.*;

String pattern = "^https?:\\/\\/[^\\s\\/$.?#].[^\\s]*$";
Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);

Matcher m = p.matcher("https://example.com");
boolean isValid = m.matches(); // true

// Find occurrences
Matcher finder = p.matcher(inputText);
while (finder.find()) {
    System.out.println(finder.group());
}

주요 사용 사례

  • 웹사이트 URL 입력 필드 검증
  • 링크 목록에서 유효한 URL 필터링
  • 크롤러의 URL 형식 사전 검증
  • 사용자 프로필 홈페이지 URL 검증
  • API 웹훅 URL 등록 전 유효성 확인

관련 패턴

email/^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-/iphone/^\+?[\d\s\-\(\)]{7,15}$/ip-address/^((25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\./date/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[/
ad · 300×250
Regex 테스터로 돌아가기
// related tools
Cron 표현식 생성기
Cron 표현식을 시각적으로 만들고 파싱합니다. 사람이 읽기 쉬운 설명과 다음 실행 시간을 미리 확인할 수 있습니다.
jwt
JWT 디코더
JWT 토큰을 디코딩하고 분석합니다. 헤더, 페이로드, 서명을 확인할 수 있습니다.
색상 변환기
HEX, RGB, HSL 등 다양한 형식으로 색상을 변환합니다.
ts
타임스탬프 변환기
Unix 타임스탬프와 날짜/시간을 양방향으로 변환합니다. ms/s, UTC/로컬, 상대 시간을 지원합니다.