免責事項: これらは非常に基本的なものであり、有効な TLD やファイル拡張子のチェックには対応していません。自己責任。
ディレクトリやファイルを考慮する必要がないと仮定すると、サブドメインなしでこれらのベース URL のみを照合するには、次の正規表現を使用できます。
(?<=^|[\n\s])(?:https?:\/\/)?(?:www\.)?[a-zA-Z0-9-.]+\.com\/?(?=$|[\n\s])
#DESCRIPTION::
# (?<=^|[\n\s]) Checks to see that what's preceding the URL is the beginning of the string, or a newline, or whitespace.
# (?:https?:\/\/)? Matches http(s) if it is there
# (?:www\.)? Matches www. if it is there
# [a-zA-Z0-9-]+ Matches "example" in "example.com" (as well as any other valid URL character; will also match subdomains)
# \.com\/? Matches .com(/)
# (?=$|[\n\s]) Checks to see that what's following the URL is the end of the string, or a newline, or whitespace.
ディレクトリとファイルも一致させる必要がある場合は、正規表現の末尾を変更して、わずかに追加する必要があります。
(?<=^|[\n\s])(?:https?:\/\/)?(?:www\.)?[a-zA-Z0-9-.]+\.com(?:(?:\/[\w]+)+)?(?:\/|\.[\w]+)?(?=$|[\n\s])
#DESCRIPTION::
# (?<=^|[\n\s]) Checks to see that what's preceding the URL is the beginning of the string, or a newline, or whitespace.
# (?:https?:\/\/)? Matches http(s) if it is there
# (?:www\.)? Matches www. if it is there
# [a-zA-Z0-9-.]+ Matches "example" in "example.com" (as well as any other valid URL character; will also match subdomains)
# \.com Matches .com
# (?: Start of a group
# (?:\/[\w]+)+ Attempts to find subdirectories by matching /, then word characters
# )? Ends the previous group. This group can be skipped, if there are no subdirectories
# (?:\/|\.[\w]+)? Matches a file extension if it is there, or a / if it is there.
# (?=$|[\n\s]) Checks to see that what's following the URL is the end of the string, or a newline, or whitespace.