1, Date
var then = new Date(2010, 0, 1);
var later = new Date(2010, 0, 1, 17, 10, 30);
var now = new Date()
later.getFullYear()
later.getMonth()
later.getDate()
later.getDay()
...........
2. RegExp
JavaScript defines a RegExp() constructor for creating objects that represent textual patterns.These patterns are described with regular expressions, and JavaScript adopts Perl's syntax for regular expressions.
Both strings and RegExp objects have methods for performing pattern matching and search-and-replace operations using regular expressions.
一对斜线之间的文本组成了一个正则表达式。这对斜线的第2个斜线后可以添加一个或多个字母,这可以改变模式的意思。
例如:
/^HTML/ // 匹配以HTML开头的字符串
/[1-9][0-9]*/ //匹配非0整数,后面可以跟任意多个数字
/\bjavascript\b/i // 匹配包含"javascript"单词,大小写敏感
RegExp objects中一些有用的方法:
例如:
var text = "testing: 1, 2, 3"; // Sample text
var pattern = /\d+/g // Mathes all instances of one or more digits
pattern.text(text) // => true: a math exists
text.search(pattern) // => 9: position of first math
text.match(pattern) // => ["1", "2", "3"]: array of all mathes
text.replace(pattern, "#"); // => "testing: #, #, #"
text.split(/\D+/); // => ["","1","2","3"]: split on non-digits.
var then = new Date(2010, 0, 1);
var later = new Date(2010, 0, 1, 17, 10, 30);
var now = new Date()
later.getFullYear()
later.getMonth()
later.getDate()
later.getDay()
...........
2. RegExp
JavaScript defines a RegExp() constructor for creating objects that represent textual patterns.These patterns are described with regular expressions, and JavaScript adopts Perl's syntax for regular expressions.
Both strings and RegExp objects have methods for performing pattern matching and search-and-replace operations using regular expressions.
一对斜线之间的文本组成了一个正则表达式。这对斜线的第2个斜线后可以添加一个或多个字母,这可以改变模式的意思。
例如:
/^HTML/ // 匹配以HTML开头的字符串
/[1-9][0-9]*/ //匹配非0整数,后面可以跟任意多个数字
/\bjavascript\b/i // 匹配包含"javascript"单词,大小写敏感
RegExp objects中一些有用的方法:
例如:
var text = "testing: 1, 2, 3"; // Sample text
var pattern = /\d+/g // Mathes all instances of one or more digits
pattern.text(text) // => true: a math exists
text.search(pattern) // => 9: position of first math
text.match(pattern) // => ["1", "2", "3"]: array of all mathes
text.replace(pattern, "#"); // => "testing: #, #, #"
text.split(/\D+/); // => ["","1","2","3"]: split on non-digits.
本文深入探讨了JavaScript中的Date对象的基本使用方法,并详细解释了如何利用正则表达式进行文本模式匹配、搜索与替换操作。通过实例演示了如何获取日期和时间的详细信息,以及如何创建和操作正则表达式来处理字符串。
160

被折叠的 条评论
为什么被折叠?



