日本一区二区免费播放_麻豆导航_久久精品99_国产性av_色婷婷噜噜久久国产精品12p_av福利资源_精品综合久久

當前位置:首頁 > 網站舊欄目 > 學習園地 > 設計軟件教程 > D語言的正則表達式例子

D語言的正則表達式例子
2010-01-13 21:14:07  作者:  來源:

D語言的正則表達式例子

Java代碼
module regexp;  
 
import std.stdio : writefln;  
import std.regexp;  
import std.c.stdio;  
 
bool isalpha(char[] c)  
{  
    RegExp myRegExp;  
    myRegExp = new RegExp("^[a-zA-Z_]+$", "");  
    return cast(bool) myRegExp.test(c);  
}  
 
bool isspace(char[] c)  
{  
     /* true if c is whitespace, false otherwise */ 
 
    RegExp myRegExp = new RegExp("^\\s+$", "");  
    return cast(bool) myRegExp.test(c);  
}  
 
bool isdigit(char[] c)  
/* true if c is a decimal digit, false otherwise */ 
{  
    RegExp myRegExp = new RegExp("^\\d+$", "");  
    return cast(bool) myRegExp.test(c);  
}  
 
bool ishexdigit(char[] c)  
/* true if c is a hexadecimal digit, false otherwise */ 
{  
    RegExp myRegExp = new RegExp("^[0-9A-F]+$", "");  
    /* If it were D code, "_" would also be valid */ 
 
    return cast(bit) myRegExp.test(c);  
}  
 
bool isoctdigit(char[] c)  
/* true if c is an octal digit, false otherwise */ 
{  
    RegExp myRegExp = new RegExp("^[0-7]+$", "");  
    return cast(bool) myRegExp.test(c);  
}  
 
bool issymbol(char[] c)  
/* true if c is legal SQL symbol, false otherwise */ 
{  
    RegExp myRegExp = new RegExp("^[\\(\\)\\[\\]\\.,;=<>\\+\\-\\*/&\\^]+$", "");  
    return cast(bool) myRegExp.test(c);  
}  
 
bool isDate(char[] c)  
/* true if c is a date, false otherwise */ 
{  
    RegExp myRegExp = new RegExp("((((19){1}|(20){1})d{2})|d{2})[01]{1}d{1}[0-3]{1}d{1}", ""); //1900  
    return cast(bool) myRegExp.test(c);  
}  
 
bool isChinese(char[] c)  
/* true if c is a chinese string, false otherwise */ 
{  
    RegExp myRegExp = new RegExp("^[\u4e00-\u9fa5]+$", "");  
    return cast(bool) myRegExp.test(c);  
}  
 
bool iscnPhone(char[] c)  
/* true if c is a china phone code, false otherwise */ 
{  
    RegExp myRegExp = new RegExp("\\d{3}-\\d{8}|\\d{4}-\\d{7}", "g");  
    return cast(bool) myRegExp.test(c);  
}  
 
bool iscnMobile(char[] c)  
/* true if c is a china Mobile code, false otherwise */ 
{  
    RegExp myRegExp = new RegExp("^((\\(\\d{2,3}\\))|(\\d{3}\\-))?13\\d{9}$", "");  
    return cast(bool) myRegExp.test(c);  
}  
 
bool iscnZip(char[] c)  
/* true if c is a china ZIP, false otherwise */ 
{  
    RegExp myRegExp = new RegExp("^[0-9]\\d{5}$", "");  
    return cast(bool) myRegExp.test(c);  
}  
 
bool iscnIDcard(char[] c)  
/* true if c is a china ID card, false otherwise */ 
{  
    RegExp myRegExp = new RegExp("\\d{15}|\\d{18}", "");  
    return cast(bool) myRegExp.test(c);  
}  
 
unittest  
{  
    /* compile with the -unittest flag to run these tests */ 
 
    writefln("Testing functions...");  
 
    assert(isalpha("a") && isalpha("A") && !isalpha("9") && isalpha("_") && isalpha("R") && !isalpha("&"));  
 
    assert(issymbol("(") && issymbol(")") && issymbol("[") && issymbol("]") && issymbol(")") &&  
      issymbol("[") && issymbol("]") && issymbol("-") && issymbol("/") && issymbol("=") && issymbol("*") &&  
      issymbol(".") && !issymbol("a") && !issymbol("0") && !issymbol("Y") && !issymbol("\\"));  
 
    assert(isdigit("0") && isdigit("7") && isdigit("9") && !isdigit("A")  && !isdigit("^") && !isdigit("G"));  
 
    assert(ishexdigit("0") && ishexdigit("7") && ishexdigit("A")  && !ishexdigit("^") && !ishexdigit("G"));  
 
    assert(isoctdigit("0") && isoctdigit("7") && !isoctdigit("8")  && !isoctdigit("A")  && !isoctdigit("^"));  
 
    assert(isspace(" ")  && isspace("\t") && !isspace("o")  && !isspace(".")  && !isspace("5"));  
 
    assert(isChinese("中文")  && isChinese("哦") && !isChinese("*.")  && !isChinese("abcd")  && !isChinese("5"));  
 
        assert(iscnPhone("010-12345678")  && iscnPhone("0710-1234567") && !iscnPhone("01-12345")  && !iscnPhone("010-12")  && !iscnPhone("0314-123456") && iscnPhone("0314-12345678-90")&& iscnPhone("0314-12345678-901") && iscnPhone("012345-12345678-901") );  
 
        assert(iscnMobile("13123456789")&& !iscnMobile("139123456789") && !iscnMobile("*.")  && !iscnMobile("abcd")  && !iscnMobile("5")  );  
 
        assert(iscnZip("100081")&& iscnZip("012346") && !iscnZip("*.")  && !iscnZip("abcd")  && !iscnZip("5")  );  
 
 
    writefln("Functions tested successfully.");  
}  
 
void main()  
{  
    /* Compile with the -debug flag for this statement to run. */ 
 
    debug writefln("Main Program.");  
 

更多信息請登陸http://61.191.27.74:802/ 最后,歡迎加入http://61.191.27.74:802/的會員


安徽新華電腦學校專業職業規劃師為你提供更多幫助【在線咨詢
主站蜘蛛池模板: 免费人成又黄又爽的视频在线 | 久热99| 九九热在线视频观看这里只有精品 | 日韩a在线| 人人看人人添人人爽 | 秋霞网韩国理伦片不卡免费看 | 九九热最新网址 | 热99re久久精品精品免费 | 国产精品亚洲片在线花蝴蝶 | 亚洲午夜精品一区二区 | 91精品久久久久久久久中文字幕 | 欧美xxxx性猛交bbbb | 久久久婷婷 | 欧美成人手机在线 | 久久波多野结衣 | 韩国19福利视频免费观看 | 国产成人91高清精品免费 | 欧美日本一区视频免费 | 久久中文字幕日韩精品 | 三级视频在线播放 | 日产日韩亚洲欧美综合搜索 | 97自拍视频| 天天摸天天做天天爽水多 | 黄 色 成 年人在线 黄 色 大 片 网站 | 国产精品第十页 | 欧美精品免费在线 | 性久久久久 | 岛国视频在线观看 | 日本天堂网在线 | 精品在线观看 | 亚洲第一区se | 欧洲第一区第二区第三区 | 青青视频免费观看在线播放 | 青青草免费在线观看视频 | 国产亚洲欧美在线 | 韩国三级久久网 | 99久热只有精品视频免费观看17 | 99伊人网 | 亚洲第一免费视频 | 人人舔人人| 男女污污黄无遮挡免费 |