Created
March 18, 2012 15:54
-
-
Save cosmo0920/2075993 to your computer and use it in GitHub Desktop.
URLが含まれてるかRegexしましょう
This file contains hidden or 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
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