special chars
CHARACTER | COMMENTS |
---|---|
?: |
non capturing group |
?= |
positive look ahead |
?! |
negative look ahead |
?<= |
positive look behind |
?<! |
negative look behind |
samples
get URL
$ echo http://www.baidu.com | awk '{for(i=1;i<=NF;i++){if($i~/^(http|ftp):\/\//)print $i}}'
http://www.baidu.com
references:
matches if exits
[!NOTE|label:samples:]
✔️ keyword.baz.com ✔️ string-keyword.baz.com ✔️ keyword-staging.bar.com ✔️ keyword-staging.foo.com
^.*keyword(?:-staging)?\.[^\]+\.com
not matche a word
[!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).)*$