none
正则表达式:一串字符里面只含有“数字”、“横杠”、“空格” RRS feed

答案

  • 你试试这个正则表达式:[\s\d-],其中\s 代表 匹配任何非空白字符。与 [^ \f\n\r\t\v] 等效;\d 等效 数字字符匹配,等效于 [0-9];[-]代表 字符集,匹配包含的任一字符。

    具体正则表达式语法参考MSDN:http://msdn.microsoft.com/zh-cn/library/ae5bf541(v=VS.90).aspx



    If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. My sample

    是不是应该加上^和$?光这样是不对的哦;)看结果:

     Regex reg = new Regex("[\\s\\d-]");
                //测试
                Console.WriteLine(reg.Match("123-456z").Success);

    正确的是:

     Regex reg = new Regex("^[\\s\\d-]+$");
                //测试
                Console.WriteLine(reg.Match("123-456z").Success);

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at:
    Spam Report

    2013年8月23日 6:43
    版主

全部回复

  • 你试试这个正则表达式:[\s\d-],其中\s 代表 匹配任何非空白字符。与 [^ \f\n\r\t\v] 等效;\d 等效 数字字符匹配,等效于 [0-9];[-]代表 字符集,匹配包含的任一字符。

    具体正则表达式语法参考MSDN:http://msdn.microsoft.com/zh-cn/library/ae5bf541(v=VS.90).aspx



    If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. My sample

    2013年8月23日 2:35
  • 你试试这个正则表达式:[\s\d-],其中\s 代表 匹配任何非空白字符。与 [^ \f\n\r\t\v] 等效;\d 等效 数字字符匹配,等效于 [0-9];[-]代表 字符集,匹配包含的任一字符。

    具体正则表达式语法参考MSDN:http://msdn.microsoft.com/zh-cn/library/ae5bf541(v=VS.90).aspx



    If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. My sample

    是不是应该加上^和$?光这样是不对的哦;)看结果:

     Regex reg = new Regex("[\\s\\d-]");
                //测试
                Console.WriteLine(reg.Match("123-456z").Success);

    正确的是:

     Regex reg = new Regex("^[\\s\\d-]+$");
                //测试
                Console.WriteLine(reg.Match("123-456z").Success);

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at:
    Spam Report

    2013年8月23日 6:43
    版主