code_junkie

What are good regular expressions?

Nov 10th, 2011
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. puts "Matched!" unless /d{3}-d{4}/.match("555-1234").nil?puts "Didn't match!" if /d{3}-d{4}/.match("Not phone number").nil?
  2.  
  3. match = /([^@]*)@(.*)/.match("[email protected]")name = match[1]domain = match[2]
  4.  
  5. /(bb|[^b]{2})/i
  6.  
  7. /^1?$|^(11+?)1+$/
  8.  
  9. def is_prime(n)
  10. str = "1" * n
  11. return str !~ /^1?$|^(11+?)1+$/
  12. end
  13.  
  14. ^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])[a-zA-Z0-9]{5,10}$
Add Comment
Please, Sign In to add comment