Solution
^\(?\w{1,3}\s*[):.]\s*
Description
Demo
Discussion
I'll take each of your regexes and output the problem in each:
1. Using src = re.sub(r'([^)])', '', src), I was removing more than the heading (...)*
The *
quantifier is greedy. It will try to the most possible characters that are not )
. This is why you get more than the heading.
2. Using src = re.sub(r'^\([^)]*\)', '', src)
, I was able to specify the start of line with ^ in the regex but it didn't get the maximum of 3 alphanumeric condition.
The *
quantifier means zero or more
. If you want 3 alphanumeric max, you need to use this quantifier: {1,3}
. It means 1, 2 or three times.
3.Using re.sub(r'^:[^)])', '',src) and re.sub(r'^.[^)])', '',src), I was not able to make the regex detect [0-9a-zA-z][0-9a-zA-z][0-9a-zA-z] followed by a . or :
Here the regex is missing the .
and :
for matching those characters respectively.