Skip to content

Instantly share code, notes, and snippets.

@ruanwz
Created September 2, 2010 01:48
Show Gist options
  • Save ruanwz/561703 to your computer and use it in GitHub Desktop.
Save ruanwz/561703 to your computer and use it in GitHub Desktop.
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)(\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 =~ "sdfds<body><p>hi</p><ul><li>one</li><li>two</li></ul></body>"
puts reg_xml =~ "<a>sdf<b>sf</a>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment