日本一区二区免费播放_麻豆导航_久久精品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/的會員


安徽新華電腦學校專業職業規劃師為你提供更多幫助【在線咨詢
主站蜘蛛池模板: 久久久久亚洲精品影视 | 高清精品一区二区三区一区 | 国产成人精品日本亚洲麻豆 | 漂亮的保姆在线播放 | 性做久久久久久坡多野结衣 | 日本美女一级黄色片 | 日本韩国一区二区三区 | 亚洲va久久久噜噜噜久久天堂 | 黄色三级三级免费看 | 久久这里只精品热免费99 | 日本免费影院 | 91伊人国产 | 波多野结衣国产精品 | 国产福利在线视频 | 麻豆视频传媒二区 | 毛片爱爱| 国产黄色大片又色又爽 | 日本污视频| 久久亚洲一级毛片 | 99视频精品全部免费免费观 | 久久永久免费中文字幕 | 日本在线观看一区二区三区 | 国产一级又色又爽又黄大片 | 色老99久久九九爱精品69堂 | 久久久久亚洲视频 | 欧美猛交xxxx免费看 | 欧美性黑人极品1819hd | 国产精品资源网站在线观看 | 国产日本高清动作片www网站 | 开心丁香婷婷深爱五月 | 日本精品一区二区在线播放 | jizzjizz18日本人 | 欧美激情一区二区三区视频 | 欧美jizz8性欧美 | 99视频久久 | 国产美女免费观看 | 国产精品人人爱一区二区白浆 | 久久国产经典 | 午夜影院私人 | 国产成人精品午夜免费 | 免费久久一级欧美特大黄 |