1 / 12
文档名称:

js常用正则表达式JSregularexpressions.doc

格式:doc   大小:48KB   页数:12页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

js常用正则表达式JSregularexpressions.doc

上传人:ttteee8 2022/6/23 文件大小:48 KB

下载得到文件列表

js常用正则表达式JSregularexpressions.doc

相关文档

文档介绍

文档介绍:js 常用正则表达式(JS regular expressions)
Integer or decimal: "[0-9]+\. {0, 1) [0~9] {0, 2) $
You can only enter numbers: "
((112) [0~9])
30|31) $" correct format; "01" to "09" and "1" to "31”.
Regular expressions that match Chinese characters: [\u4e00-\u9fa5]
Matches double byte characters (including Chinese characters), :[ \x00~\xff]
Application: calculates the length of a string (a double byte character length 2, ASCII character length 1)
String, prototype. len=function () {
Return this, replace (/["\x00~\xff]/g, AA). Length:
}
Regular expression for matching empty lines: \n[\s|]*\r
Regular expression matching HTML Tags: < > (. *) (*) (*) <\/ >| < (.*) \/>
Regular expression matching both spaces: ( \s*) | (\s*$)
Application: there is no trim function like VBScript in JavaScript, so we can use this expression to implement, as follows:
String, prototype, trim = function () {
Return ( / ("\s*) | (\s*$) /g,;
Break and transform IP addresses using regular expressions:
Here is a Javascript program that uses regular expressions to match IP addresses and convert IP addresses into corresponding values:
Function IP2V (IP)
{
Re=/ (\d+). (\d+). (\d+). (\d+) /g, the regular expression / / IP address
If (re. test (IP)) {
Return, RegExp. $l*Math. pow (255, 3)) +RegExp. $2*Math. pow (255,2)) +RegExp, $3*255+RegExp. $4*1
) else {
Throw new Error ("Not a valid IP address!z/) However, if the program does not use regular expressions, it may be simpler to decompose it directly with the split function:
Var ip= "10. 100. 20. 168”〃
Ip=ip. split (〃, 〃)
Alert (IP value is: +)
(ip[0]*255*255*255+ip[l]*255*255+ip[2]*255+ip[3]*1)
A regular expression that matches the Email address: \w+ ([—+. ]\w+), *@\w+ ([-. ] \w+), *\. \w+ ([-. ] \w+) *
Regular expression matching. URL: http:// ([\w-]+\.) +[\w~] + (/[\w- /%&=]*?)?
Use regular expressions to restrict text boxes in web forms to enter content:
Limited input with regular expressions Chinese: onkeyup= valu