其它脚本

关注公众号 jb51net

关闭
XRegExp V2.0 JavaScript正则表达式库

XRegExp V2.0 JavaScript正则表达式库

热门排行

简介

XRegExp 是一个开源的 JavaScript 库提供一个参数化、可扩展的支持各种浏览器的正则表达式的实现库,支持附加语法、标志以及方法。

XRegExp 完全兼容 ES3 和 ES5 正则表达式使用习惯,已通过测试的浏览器包括:Internet Explorer 5.5–8, Firefox 2–3.6, Safari 3–4, Chrome 1–4, and Opera 9.5–10.5.

在线测试://regexpal.com/

XRegExp(pattern, [flags])
Accepts a pattern and flags; returns a new, extended RegExp object. Differs from a native regular expression in that additional syntax and flags are supported and cross-browser regex syntax inconsistencies are ameliorated.

Parameters: •pattern : String or RegExp
The regular expression pattern String, or an existing RegExp object to copy.
•flags : String [optional]
The regular expression flags; may include non-native flags s and x. Flags cannot be provided when constructing one RegExp from another.

Returns: •RegExp
An extended regular expression object.
[code]
var regex = XRegExp("(?<month> [0-9]+ ) [-/.\\s] # month\n\
(?<day> [0-9]+ ) [-/.\\s] # day \n\
(?<year> [0-9]+ ) # year ", "x");

var input = "04/20/2009";
input.replace(regex, "${year}-${month}-${day}"); // "2009-04-20"

var match = regex.exec(input);
match.month; // "04"

regex instanceof RegExp; // true
regex.constructor == RegExp; // true
[/code]

大家还下载了