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.
- Prepare
- Python
- Regex and Parsing
- Hex Color Code
- Discussions
Hex Color Code
Hex Color Code
Sort by
recency
|
386 Discussions
|
Please Login in order to post a 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}'
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")