Sort by

recency

|

387 Discussions

|

  • + 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)))
    
  • + 1 comment

    None of the regex patterns I see here will exclude #BED and #Cab. Am I missing something?

    This is how I did it

    pattern = r'(?<!^)#[0-9A-Fa-f]{3,6}'

  • + 0 comments

    import re N = int(input()) for _ in range(N): inp = input() m = re.search(r"^#[A-Fa-f0-9]*", inp) if not m: t = re.findall(r"#[A-Fa-f0-9]{6}|#[A-Fa-f0-9]{3}", inp) if t!=[]: print(*t, sep="\n")