전체 글
-
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..
-
Practice>Python>Regex and Parsing>Regex Substitutionhackerrank.com 2019. 4. 9. 12:58
hackerrank.com Regex Substitution Problem Link : https://www.hackerrank.com/challenges/re-sub-regex-substitution/problem Difficulty : Medium Tip It's not a simple replacing string You should aware of lookaround, lookahead and lookbegind re.sum(r" && ", ' and ', input()) This is not going to work, if input is like ' && && ' the space in the middle of two && it consumed when the first && is matche..
-
Practice>Python>Regex and Parsing>Re.start() & Re.end()hackerrank.com 2019. 4. 4. 12:43
hackerrank.com Re.start() & Re.end() Problem Link : https://www.hackerrank.com/challenges/re-start-re-end/problem Difficulty : Easy Tip re.search() start() and end() methods are described in problme description re.finditer() is a key method, as it return all occurences which is matched with given regular expression start() == end() from re.finditer() start() != end() from re.search() So, we shou..