regex
special chars
CHARACTER
COMMENTS
?:
non capturing group
?=
positive look ahead
?!
negative look ahead
?<=
positive look behind
?<!
negative look behind
cheatsheet
[!NOTE|label:references:]
get URL
$ echo http://www.baidu.com | awk '{for(i=1;i<=NF;i++){if($i~/^(http|ftp):\/\//)print $i}}'
http://www.baidu.com
# or: https://www.commandlinefu.com/commands/view/4174/match-a-url
$ egrep 'https?://([[:alpha:]]([-[:alnum:]]+[[:alnum:]])*\.)+[[:alpha:]]{2,3}(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)?'
matches if exits
[!NOTE|label:samples:]
✔️ keyword.baz.com ✔️ string-keyword.baz.com ✔️ keyword-staging.bar.com ✔️ keyword-staging.foo.com
^.*keyword(?:-staging)?\.[^\]+\.com
[!NOTE|label:samples:]
❌ /etc/kubernetes/config.backup/config.backup.20220303/admin.conf ✔️ /etc/kubernetes/pki/admin.conf
^((?!backup).)+(admin|kubelet)\.conf$
not matches multiple keywords
[!NOTE|label:samples:]
❌ foo-jenkins.domain.com ❌ foo-jenkins.domain.com/Monitor/ ❌ marslo.github.com ❌ 127.0.0.1
^((?!.*\-jenkins\.[^\.]+\.com|.*Monitor/$|.*detail.*pipeline|.*api|marslo.github.*|shields.io|127.0.0.1|0.0.0.0|localhost).)*$
Last updated
Was this helpful?