Sort by

recency

|

389 Discussions

|

  • + 0 comments
    import re
    pattern = r'#[0-9A-Fa-f]{6}\b|#[0-9A-Fa-f]{3}\b'
    n = int(input().strip())
    inside = False
    for _ in range(n):
        t = input()
        if "{" in t: 
            inside = True
        elif "}" in t: 
            inside = False
        elif inside:
            [print(x) for x  in re.findall(pattern,  t)]
    
  • + 0 comments

    My solution, matching only within {} sections

    import re
    
    n = int(input())
    
    css=""
    for i in range(n):
        css += input()
    
    rsection = r"{.*?}"
    rhexcode = r"#[0-9A-Fa-f]{6}|#[0-9A-Fa-f]{3}"
    
    sections = re.findall(rsection,css)
        
    for s in sections:
        hexcodes = re.findall(rhexcode,s)
        for hc in hexcodes:
            print(hc)
    
  • + 0 comments
    import re
    
    pattern = r'#[0-9ABCDEFabcdef]{3,6}[();,?]'
    
    N = int(input())
    
    for i in range(N):
        txt = input()
        li = re.findall(pattern, txt)
        if len(li) > 0:
            for a in li:
                print(a[:-1])
    
  • + 0 comments
    import re
    
    for i in range(int(input())):
        s = input()
        matches = re.findall(r"[.:\s](#[0-9A-Fa-f]{6}|#[0-9A-Fa-f]{3})", s)
        if matches:
            print(*matches, sep="\n")
    
  • + 0 comments
    import re
    p1 = r'{[^{}]*}'
    p2 = r'#[\da-fA-F]{3,6}'
    t = ''.join(input() for _ in range(int(input())))
    t = ''.join(re.findall(p1, t))
    print('\n'.join(re.findall(p2, t)))