tool::regex-guide
regex url
/^https?:\/\/[^\s\/$.?#].[^\s]*$/i
URL検証
正規表現パターン
/^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.comhttpまたはhttpsプロトコルで始まるURLを検証するパターンです。ドメイン、パス、クエリ文字列などの標準的なURL構成要素を許可します。ftpやmailtoなどの他のスキームには別途パターンが必要です。
言語別の使用方法
主なユースケース
- ▸ウェブサイトURL入力フィールドの検証
- ▸リンクリストから有効なURLをフィルタリング
- ▸クローラーのURL形式事前検証
- ▸ユーザープロフィールのホームページURL検証
- ▸Webhook URL登録前の有効性確認
関連パターン
ad · 300×250
// related tools