免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 883 | 回复: 0
打印 上一主题 下一主题

first touch to Regex [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-09-13 18:29 |只看该作者 |倒序浏览
Oh, I haven’t come here for two weeks. What I am busy with is coding. I should complete all the coding tasks. Bad luck! I must code day after day until the code is over. I’ll recall the problems I encountered those days, and record here to share with all of you. Ok, let’s discuss the problems start with Regex (Regular Expression).

The following explanation to define the regular expression is cited from the java tutorials of Sun Microsystems Corporation. Regular expressions are a way to describe a set of strings based on common characteristics shared by each string in the set. They can be used to search, edit, or manipulate text and data. You must learn a specific syntax to create regular expressions — one that goes beyond the normal syntax of the Java programming language. Regular expressions vary in complexity, but once you understand the basics of how they're constructed, you'll be able to decipher (or create) any regular expression.

I haven’t used the regular expressions before I have to solve how to check whether the IP address format is right or wrong. I haven’t dealt with the similar problem since I entered the college. Now, I’m in the corporation, not in the college. I opened the browser and search how to check IP address. Of course, I found abundant information about it. I think it’s the best way to check IP address with regular expression. The following JavaScript codes show the power of the regular expression.
function checkIp(ipAddress){ var exp=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
var reg=ipAddress.match(exp);
if(reg==null)  {
       return false;
}else{
       return true;
}
}
You can judge some string is blank or not with the following javascript function.
function checkBlank(input){
    return Boolean( /^\s*$/.test( input ) );
}
Of course, you can do many things with regular expressions. You can search, edit, or manipulate text and data with abbreviated regular expressions. I’m a novice to it. I decide to learn it earnestly and master it!




本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/29515/showart_381250.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP