Created
August 26, 2010 23:47
-
-
Save ruanwz/552488 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reg2=/^[\w!#\$%&'*+\/=?`{|}~^-]+ #only allow to start with these symbols | |
(?:\.[\w!#\$%&'*+\/=?`{|}~^-]+)* # the user name can contain dot | |
@ # @ symbol | |
(?:[a-zA-Z0-9-]+\.)+ # domain | |
[a-zA-Z]{2,6}$ # the last part of domain | |
/x # ignore spaces | |
reg=/(?<allow_char> [\w!#\$%&'*+\/=?`{|}~^-]+){0} #only allow to start with these symbols | |
(?<script_tag> script){0} | |
^\g<allow_char>+ | |
(?:\.\g<allow_char>)* # the user name can contain dot | |
@ # @ symbol | |
(?:[a-zA-Z0-9-]+\.)+ # domain | |
[a-zA-Z]{2,6}$ # the last part of domain | |
/x # ignore spaces | |
def encrypt str | |
str.gsub(/[A-Z]/) {|s| s.next} | |
end | |
puts '[email protected]'[reg] # => [email protected] | |
puts '[email protected]'[reg] # => [email protected] | |
puts '[email protected]'[reg] # => nil | |
puts 'j*[email protected]'[reg] # => j*[email protected] | |
puts '[email protected]'[reg] # => [email protected] | |
puts '[email protected]'[reg] # => nil | |
puts "<script>alert('boo');</script>\[email protected]"[reg] # => [email protected] | |
puts encrypt "HAL" | |
reg_xml=/((?<tag> \<\w+\> \w*\g<tag>* \<\/\w+\>))/x | |
puts reg_xml =~ "<body></body>" | |
puts reg_xml =~ "<body><p>hi</p></body>" | |
puts reg_xml =~ "<body><p>hi</p><ul></ul></body>" | |
puts reg_xml =~ "<body><p>hi</p><ul><li>one</li><li>two</li></ul></body>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment