# Create an example of how to test for correctly formed URLstester=VerEx.newdostart_of_linefind'http'maybe's'find'://'maybe'www.'anything_but' 'end_of_lineend# Create an example URLtest_url="https://www.google.com"# Use it just like a regular Ruby regex:puts'Hooray! It works!'iftester.match(test_url)puts'This works too!'iftester=~test_url# Print the generated regex:putstester.source# => /^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$/
是不是很性感啊?还有各个语言的版本:
Ruby
C#
Python
Java
Groovy
PHP
Haskell
C++
Objective-C
You need to Sign in before reply, if you don't have an account, please Sign up first.