-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgrep-url
More file actions
executable file
·24 lines (21 loc) · 786 Bytes
/
Copy pathgrep-url
File metadata and controls
executable file
·24 lines (21 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/sh
#
# Grep url from stdin.
#
# Source: https://gist.github.com/GuillaumeLestringant/36c11afcc35c8c5b9123
proto="((?:https?|ftp)://|)"
id="?:\S+(?::\S*)?@"
ip_excluded="(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})"
ip_included="(?:1\d\d|2[01]\d|22[0-3]|[1-9]\d?)(?:\.(?:2[0-4]\\d|25[0-5]|1?\\d{1,2})){2}(?:\.(?:1\d\d|2[0-4]\d|25[0-4]|[1-9]\d?))"
ip="$ip_excluded$ip_included"
chars="a-z\x{00a1}-\x{ffff}"
base="(?:[${chars}0-9]-*)*[${chars}0-9]+"
host="(?:$base)"
domain="(?:\.$base)*"
tld="(?:\.(?:[${chars}]{2,}))"
fulldomain=$host$domain$tld"\.?"
name="(?:$ip|$fulldomain)"
port="(?::\d{2,5})?"
path="(?:[/?#]\S*)?"
exec grep ${1:+"$@"} -P -i -e "^($proto($id)?$name$port$path)\$"
# vim: set ft=sh :