帮助轻松构建正规表达式的JavaScript类库:VerbalExpressions
jopen
10年前
VerbalExpressions是一个帮助轻松构建正规表达式的JavaScript类库。
还其它编程语言的移植实现:
校验正确的URL
// Create an example of how to test for correctly formed URLs var tester = VerEx() .startOfLine() .then( "http" ) .maybe( "s" ) .then( "://" ) .maybe( "www." ) .anythingBut( " " ) .endOfLine(); // Create an example URL var testMe = "https://www.google.com"; // Use RegExp object's native test() function if( tester.test( testMe ) ) alert( "We have a correct URL "); // This output will fire else alert( "The URL is incorrect" ); console.log( tester ); // Ouputs the actual expression used: /^(http)(s)?(\:\/\/)(www\.)?([^\ ]