Skip to content

Instantly share code, notes, and snippets.

@cosmo0920
Created March 18, 2012 15:54
Show Gist options
  • Save cosmo0920/2075993 to your computer and use it in GitHub Desktop.
Save cosmo0920/2075993 to your computer and use it in GitHub Desktop.
URLが含まれてるかRegexしましょう
import Text.Regex.Posix
main = do name <- getLine
print (checkURL name)
-- URLの正規表現を定める
urlRegex :: [Char]
urlRegex = ".*(https?|ftp)(://[-_.!~*\'()a-zA-Z0-9;/?:@&=+$,%#]+).*$"
-- t.coのURL長
tcoLength :: Int
tcoLength = length "http://t.co/xxxxxxx"
-- その文字列、正規表現ですか?
checkURL :: (Monad m, Num b, RegexLike Regex (m a)) => m a -> m b
checkURL url = if url =~ urlRegex then
return () >> return tcoLength
else url >> return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment