且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Jquery格式YY / MM / DD的正则表达式

更新时间:2023-02-26 14:14:26

/;



无效。

它告诉我一个错误:

正则表达式中的语法错误。



请帮助....

问候

Harshal Raut


如果你想要像2013/12/25这样的日期格式的正则表达式,试试这个

(\d){4}(\ /)([0] [1-9] | [1] [012])(\ /)([0] [ 1-9] | [12] [1-9] | [3] [01])



要在代码中使用它,请说java,javascript或c#,你将不得不用'\'来逃避'\'。ockquote>

你的实际正则表达式工作正常,如果我把它送到Expresso它甚至可以工作 - 问题是字符串分隔符。你用'/'分隔了字符串,但你的字符串也包含'/'字符,它们将作为字符串的结尾....如果你使用不同的字符串分隔符(例如双引号),它应该可以正常工作。

Hi team,

I want to use regular expression for Date Format in YYYY/MM/DD.
I am trying this:
/^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$/;

It not work.
its show me an error:
Syntax error in regular expression.

Please kindly help....
Regards
Harshal Raut

/;

It not work.
its show me an error:
Syntax error in regular expression.

Please kindly help....
Regards
Harshal Raut


If you want regex for date format like 2013/12/25, try this
(\d){4}(\/)([0][1-9]|[1][012])(\/)([0][1-9]|[12][1-9]|[3][01])


To use this in your code say java, javascript, or c#, you will have to escape the '\' with '\'.


Your actual Regex works fine, if I feed it into Expresso it even works - the problem is the string delimiters. You have delimited the string with '/' but your string also contains '/' characters, which will act as the end of the string.... If you use a different string delimiter (double quotes for example) it should work fine.