LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: jiazhengw

多发发一些有意思的题做做呀![+sed/awk/regex练习]

[复制链接]
 楼主| 发表于 2006-3-15 14:33:25 | 显示全部楼层
Post by johnny_jiang

关于第5个小题,网络地址应该为9.80.0.0,按照要求是不是需要匹配如下的几段:
1. 9.80.1.15 ~ 9.80.255.255
2. 9.81.0.0   ~ 9.81.255.255
3. 9.82.0.0   ~ 9.82.255.255
4. 9.83.0.0   ~ 9.83.253.100




我的这题考虑得太少了!现在看来,好多还得重做。!
回复 支持 反对

使用道具 举报

发表于 2006-3-15 22:14:06 | 显示全部楼层
Post by jiazhengw
是的,我是从个位判断的,个位如果是0,则十位可以是[1-9],依此类推。如果从十位判断也可以,十位如果是9,则个位可以是[0-8],这样也可以。我觉得用这样的方法那如果是三位数那岂不是长得将人看晕了,呵呵!总觉得有简单的方法,但想不出。

yeah, its basically a factorial formula
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-16 17:08:52 | 显示全部楼层
大家最后一题有没有做出来的。我做了好多次,用egrep 就是出不了正确的结果。也不知是为什么,不过发现一个小东东:如果单独的<出现的话,可以不用转义,如果和\同时出现的话,就要转义,即:匹配\<,要用\\\<。
回复 支持 反对

使用道具 举报

发表于 2006-3-19 01:13:48 | 显示全部楼层
No many people are interested in those exams looks like... well here is what I did for the IP one:

  1. 1.
  2. /(([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))\.){3}([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))$/

  3. 2.
  4. A class:
  5. ([1-9][0-9]?|1[0-2][0-7])\.(([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))\.){2}([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))

  6. 3.
  7. B class:
  8. 1(2[89]|[3-8][0-9]|9[01])\.(([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))\.){2}([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))

  9. 4.
  10. C class:
  11. 19[2-9]|2([01][0-9]|2[0-3])\.(([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))\.){2}([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))

  12. 5.
  13. 9.80.1.15 - 9.83.253.100 的所有IP表达式(netmask = 255.252.0.0)
  14. 9\.8(0\.(1\.(1[5-9]|[2-9][0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))|([2-9]|[1-9][0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5])\.([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))))|[12](\.([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))){2}|3\.(([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-2]))\.([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))|253\.([1-9]?[0-9]|100)))
复制代码

Please check...
回复 支持 反对

使用道具 举报

发表于 2006-3-20 00:20:00 | 显示全部楼层
Post by yongjian
No many people are interested in those exams looks like... well here is what I did for the IP one:

  1. 1.
  2. /(([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))\.){3}([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))$/
  3. [color=green]passed[/color]

  4. 2.
  5. A class:
  6. ([1-9][0-9]?|1[0-2][0-7])\.(([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))\.){2}([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))
  7. [color=red]
  8. echo 1.0.00.254 | egrep 'regexp'          echo back
  9. echo 192.168.0.1 | egrep 'regexp'        echo back
  10. not passed
  11. [/color]

  12. 3.
  13. B class:
  14. 1(2[89]|[3-8][0-9]|9[01])\.(([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))\.){2}([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))
  15. [color=red]
  16. echo 128.0.00.1 | egrep 'regexp'         echo back
  17. not passed
  18. [/color]

  19. 4.
  20. C class:
  21. 19[2-9]|2([01][0-9]|2[0-3])\.(([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))\.){2}([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))
  22. [color=red]
  23. also 00 problem
  24. not passed
  25. [/color]

  26. 5.
  27. 9.80.1.15 - 9.83.253.100 的所有IP表达式(netmask = 255.252.0.0)
  28. 9\.8(0\.(1\.(1[5-9]|[2-9][0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))|([2-9]|[1-9][0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5])\.([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))))|[12](\.([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))){2}|3\.(([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-2]))\.([1-9]?[0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))|253\.([1-9]?[0-9]|100)))
  29. [color=red]
  30. echo 9.81.0.256 | egrep 'regexp'            echo back
  31. not passed
  32. [/color]
复制代码

Please check...


yongjian兄,我不确定我在测试中有没有key错,我感觉好像是我搞错了,请大家帮忙测试一下吧。
回复 支持 反对

使用道具 举报

发表于 2006-3-20 03:11:56 | 显示全部楼层
May have problems in there... I hated numbers after I've done them... See if anyone can find out.
回复 支持 反对

使用道具 举报

发表于 2006-3-23 06:40:34 | 显示全部楼层
This is how I did for the last special char matching.
  1. '[^\]*\\"t\\"[^\]*\\<user@domain\.com\\>[^\]*\\"b\\"\.'
  2. An easy one is like '\([^\]*\\\)*"\.'
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-28 10:45:51 | 显示全部楼层
Post by yongjian
This is how I did for the last special char matching.
  1. '[^\]*\\"t\\"[^\]*\\<user@domain\.com\\>[^\]*\\"b\\"\.'
  2. An easy one is like '\([^\]*\\\)*"\.'
复制代码


怎么yongjian兄的这个正则我看不懂呀,其中的 [^\] 是什么意思?除了反斜杠都匹配吗?那就不仅仅匹配字符with和and,还有很多东东了,是不是我题意理解错了?请yongjian版主指点。
回复 支持 反对

使用道具 举报

发表于 2006-3-29 02:18:55 | 显示全部楼层
ya, [^\]* means match anything not \, but it ends at the next closest \, so [^\]*\\ only match "with ".
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-30 16:19:02 | 显示全部楼层
哦,原来是这样的啊,I see,多谢!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表