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
  • 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 309 Discussions, By:

recency

Please Login in order to post a comment

  • veera_r
    6 days ago+ 0 comments
    import re
    for _ in range(int(input())):
        s = input()
        if re.search(r'^\s.*(#[\da-fA-F]{3,6})', s):
            print(*re.findall(r'#[\da-fA-F]{3,6}', s), sep='\n')
    
    0|
    Permalink
  • ratulmodak2014
    2 weeks ago+ 0 comments
    import re
    for i in range(int(input())):
        [print(match[0]+match[1]) for match in re.findall(r'([#]{1})([0-9a-fA-F]{3,6})([;,\\)])', input())]
    
    0|
    Permalink
  • Jabboscurio
    2 weeks ago+ 0 comments
    import re
    
    for _ in range(int(input())):
        for i in re.findall(r'(?<=[ :,])#[0-9A-Fa-f]{3,6}', input()):
            print(i)
    
    0|
    Permalink
  • Seal0220
    3 weeks ago+ 0 comments

    There is a tab/whitespace (\s) at the beginning of the line having HEX :

    import re
    for _ in range(int(input())):
        s = input()
        if re.search(r'^\s.*(#[\da-fA-F]{3,6})', s):
            print(*re.findall(r'#[\da-fA-F]{3,6}', s), sep='\n')
    
    0|
    Permalink
  • mars_09galaxy
    3 weeks ago+ 0 comments

    python3

    s=''''''
    for _ in range(int(input())):
        s=s+input()+'\n'
    mat = re.findall(r'#[a-fA-F0-9]{3,6}\s{0,}[,);]',s)   
    for i in mat:
        if ';' or ',' or ')' or '\n' in i:
            a=i.strip(";),\n")
            print(a)
    
    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