正则表达式

php代码:define('VALID_IP', '10\.1\.[\d]{1,3}\.[\d]{1,3}');中的[\d]{1,3}\是什么意思?

[\d]:匹配任意一个0-9的数字
x{1,3}:匹配1个到3个“x”字符
和在一起就是匹配1个到3个0-9的数字

 

 用于自己看的文章链接:

http://see.xidian.edu.cn/cpp/html/1428.html

http://blog.chinaunix.net/uid-479984-id-2114941.html

http://fuzhong1983.blog.163.com/blog/static/168470520103761330632/

http://developer.gnome.org/glib/stable/glib-Perl-compatible-regular-expressions.html#g-regex-new

 

匹配html的嵌入代码
  1. <[^>]*>


匹配[....]的嵌入码
  1. \[[^]]\{1,\}\]


删除仅由空字符组成的行
  1. sed '/^[[:space:]]*$/d' filename


匹配html标签
  1. /\(<[^>]*>\)/
例如:从html文件中剔除html标签
  1. sed 's/\(<[^>]*>\)//g;/^[[:space:]]*$/d'  file.html


例如:要从下列代码中去除"[]"及其中包括的代码
  1. [b:4c6c2a6554][color=red:4c6c2a6554]一. 替换[/color:4c6c2a6554][/b:4c6c2a6554]
  2. sed 's/\[[^]]\{1,\}\]//g' filename


匹配日期:
  1. Month, Day, Year [A-Z][a-z]\{3,9\}, [0-9]\{1,2\}, [0-9]\{4\}
  2. 2003-01-28 或 2003.10.18 或 2003/10/10 或 2003 10 10
  3. \([0-9]\{4\}[ /-.][0-2][0-9][ /-.][0-3][0-9]\)

匹配IP地址
  1. \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)
  2. \(\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\)


匹配数字串
  1. [-+]*[0-9]\{1,\} 整数
  2. [-+]*[0-9]\{1,\}\.[0-9]\{1,\}  浮点数


从字串中解析出两个子串(前2各字符和后9个字符)
  1. echo "WeLoveChinaUnix"|sed -e 'H;s/\(..\).*/\1/;x;s/.*\(.\{9\}\)$/\1/;x;G;s/\n/ /'
  2. We ChinaUnix


分解日期串
  1. echo 20030922|sed 's/\(....\)\(..\)\(..\)/\1 \2 \3/'|read year month day
  2. echo $year $month $day


文件内容倒序输出
  1. sed '1!G;h;$!d'  oldfile >newfile
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值