Jump to content

Hex colors


[DMC]

Recommended Posts

  
function isColorCode(str) 
  if (string.find(str, "^#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$")) return true 
  return false 
end 
function isContainingColorCode(str) 
  if (string.find(str, "#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]")) return true 
  return false 
end 
function isBeginningWithColorCode(str) 
  if (string.find(str, "^#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]")) return true 
  return false 
end 
  

examples:

  
isColorCode("#ff00ff is cool color") -- false 
isColorCode("#ff0000") -- true 
isColorCode("i like this color: #00ff00") -- false 
  
isContainingColorCode("#ff00ff is cool color") -- true 
isContainingColorCode("#ff0000") -- true 
isContainingColorCode("i like this color: #00ff00") -- true 
  
isBeginningWithColorCode("#ff00ff is cool color") -- true 
isBeginningWithColorCode("#ff0000") -- true 
isBeginningWithColorCode("i like this color: #00ff00") -- false 
  

btw: i have written this thing, but not tested it ;)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...