We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Python
  3. Regex and Parsing
  4. Hex Color Code
  5. Discussions

Hex Color Code

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 330 Discussions, By:

recency

Please Login in order to post a comment

  • avoscanemile
    7 days ago+ 0 comments

    lol

    print("\n".join(re.findall(r"#[A-Fa-f0-9]{3}(?=;|,|\))|#[A-Fa-f0-9]{6}(?=;|,|\))", "\n".join([input() for _ in range(int(input()))]))))
    
    0|
    Permalink
  • indrajit411
    1 week ago+ 0 comments
    import re
    
    pattern = re.compile(r"(#[\da-f]{3}|#[\da-f]{6})(?=[;,)])", re.IGNORECASE)
    
    N = int(input())
    
    ls = [input() for _ in range(N)]
    S = "\n".join(ls)
    
    if pattern.search(S):
        for match in re.findall(pattern, S):
            print(match)
    
    0|
    Permalink
  • s_sriram_w
    2 weeks ago+ 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    import re
    
    def hexfinder(css):
    
        blocks = re.findall(r'\{([^}]+)\}', css)
        pattern = r'#(?i:[0-9a-f]{6}|[0-9a-f]{3})'
        for block in blocks:
            matches = re.findall(pattern, block)
            for match in matches:
                print(match)
    
    if __name__ == '__main__':
        num_lines = int(input())
        total_input = '\n'.join(input() for _ in range(num_lines))
        hexfinder(total_input)
    
    0|
    Permalink
  • medyk_pawel
    3 weeks ago+ 0 comments
    import re
    
    pat = re.compile(r'(#[A-Fa-f0-9]{3}|#[A-Fa-f0-9]{6})\s*[,;)]')
    
    n = int(input())
    for _ in range(n):
        css_color_codes = pat.findall(input())
        if css_color_codes:
            print(*css_color_codes, sep='\n')
    
    0|
    Permalink
  • pavel_ekshine
    4 weeks ago+ 1 comment
    import re
    
    p = re.compile(r"(#[abcdef0-9]{3,6})\S",re.I)
    
    for _ in range(int(input())):
        l = input()
        for m in p.findall(l):
            print(m)
           
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy