hackerrank.com
-
Practice>Python>Regex and Parsing>Validating UIDhackerrank.com 2019. 4. 16. 13:20
hackerrank.com Validating UID Problem Link : https://www.hackerrank.com/challenges/validating-uid/problem Difficulty : Easy Tip If we sort a given string, we can wrtie regular expression more easier Here is how to sort string l = [s[i] for i in range(len(s))] l.sort() l = ''.join(l) Write regular expressoin for each conditions Find 2 uppercases from sorted string Find 3 number from sorted string..
-
Practice>Python>Regex and Parsing>Detect HTML Tags, Attributes and Attribute Valueshackerrank.com 2019. 4. 15. 12:49
hackerrank.com Detect HTML Tags, Attributes and Attribute Values Problem Link : https://www.hackerrank.com/challenges/detect-html-tags-attributes-and-attribute-values/problem Difficulty : Easy Tip Using handle_starttag() is enough for this problem Print attributes as problem description Solution from html.parser import HTMLParser class MyHTMLParser(HTMLParser): def handle_starttag(self, tag, att..
-
Practice>Python>Regex and Parsing>HTML Parser - Part 2hackerrank.com 2019. 4. 15. 12:44
hackerrank.com HTML Parser - Part 2 Problem Link : https://www.hackerrank.com/challenges/html-parser-part-2/problem Difficulty : Easy Tip Here is pythn3 html parser to import from html.parser import HTMLParser strip() is a key method to remove any whitespace character Solution from html.parser import HTMLParser class MyHTMLParser(HTMLParser): def handle_data(self, data): if data.strip(): print("..
-
Practice>Python>Regex and Parsing>HTML Parser - Part 1hackerrank.com 2019. 4. 15. 12:25
hackerrank.com HTML Parser - Part 1 Problem Link : https://www.hackerrank.com/challenges/html-parser-part-1/problem Difficulty : Easy Tip Path to import, is differenct as per Python2/3 Problem description is written for Python2 So, for Python3 please refere below. from html.parser import HTMLParser Don't forget to print attrs in handle_startendtag() method Solution from html.parser import HTMLPa..
-
Practice>Python>Regex and Parsing>Hex Color Codehackerrank.com 2019. 4. 12. 13:16
hackerrank.com Hex Color Code Problem Link : https://www.hackerrank.com/challenges/hex-color-code/problem Difficulty : Easy Tip We should use lookahead in regular expression #{1}[0-9A-Fa-f]{3,6} This regular expression have a problem, because it capture from the beginning of the sentence So, we should put lookahead, to exclude if # is started from the beginning of the sentence (?
-
Practice>Python>Regex and Parsing>Validating and Parsing Email Addresseshackerrank.com 2019. 4. 12. 12:32
hackerrank.com Validating and Parsing Email Addresses Problem Link : https://www.hackerrank.com/challenges/validating-named-email-addresses/problem Difficulty : Easy Tip Two email methods are not enough to resolve We need regular expression to validate email address pattern = '[a-zA-Z](\w|-|\.)*@[a-zA-Z]*\.[a-zA-Z]{0,3}$' This is a pattern to capture email Solution import email.utils import re p..
-
Practice>Python>Regex and Parsing>Validating phone numbershackerrank.com 2019. 4. 11. 13:04
hackerrank.com Validating phone numbers Problem Link : https://www.hackerrank.com/challenges/validating-the-phone-number/problem Difficulty : Easy Tip Phone number is started with 7, 8 or 9 Rest of phone number is consist of 0~9 its length is 10 Start with 7, 8 or 9 [789]{1} 9 digiits [0123456789]{9} should be end as the length is 1 [789]{1}[0123456789]{9}$ Solution import re N = int(input()) fo..
-
Practice>Python>Regex and Parsing>Validating Roman Numeralshackerrank.com 2019. 4. 11. 12:47
hackerrank.com Validating Roman Numerals Problem Link : https://www.hackerrank.com/challenges/validate-a-roman-number/problem Difficulty : Easy Tip Problem itself is simple We should under stand what is roman number character Here is regular expression, to capture roman number chracter (^(?=[MDCLXVI])M*(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$) This allows MMMM, so it lead the failure of..