[[:digit:]]等同于字符bash

时间:2017-06-28 14:00:47

标签: regex bash

对于bash中使用的数字,等同于[[:digit:]]的字母字符的正则表达式标识符是什么?我的男人页面擦洗技巧今天不是很好。

2 个答案:

答案 0 :(得分:1)

  • man bash并搜索"正则表达式"导致指向正则表达式(3)
  • 的段落
  • man 3 regex部分"另见"指向正则表达式(7)
  • man 7 regex列出了可用的字符类,包括数字以及您之后的 alpha

答案 1 :(得分:0)

如果我找对你,你需要character class字母

[[:alpha:]]

如果您正在寻找字母以外的任何内容,那么

[^[:alpha:]] # well the ^ in the beginning of a range negates it

[ article ]是关于Regex的绝佳读物。

要从文件或输入中获取有效 IP地址,我会使用以下技巧:

$ cat testfile.ip
Well this is a small para on IP addresses. Well to start with a string 
like 172.217.26.206 represents an IP address. Well, in this case it
is Google's IP. To put it short an IP like 192.168.0.16 is the token by
which a computer connected to internet is known to the outside wolrd. It 
is all numbers game! Really ! But as humans can't remember such crazy
numbers, some fellow devised a mechanism whereby we can call a computer 
by names like 'puppy' or 'vodoo'. This mechanism is called the DNS system 
whereby a computer is in charge of redirecting you to '192.168.0.34' in 
case you asked for 'vodoo' and '192.168.234.255' in case you asked for 
'puppy'. Well you've gateways as if you're going into some big cities. So 
you'll often here "You have the wrong gateway, mine is the right one 
which is 192.168.0.1." Well you have IPV6 addresses which are evern 
crazier numbers. Also, you do have wrong IP addresses like 
'288.134.43.22' and '999.1.0.255'. Aha ! You're in no man's land if you 
are assigned these IPS. Oh ! are you an alien? Sounds scary. Aww. Bye
$ grep -oP '[\d]{0,3}\.[\d]{0,3}\.[\d]{0,3}\.[\d]{0,3}' testfile.ip |
awk -v FS="." '{for(i=1;i<=NF;i++){
if($i>=0 && $i<=255){continue;}else{next;}
}}1'
172.217.26.206
192.168.0.16
192.168.0.34
192.168.234.255
192.168.0.1