How to delete comments that are on the same line as the string i need with regex

Solution for How to delete comments that are on the same line as the string i need with regex
is Given Below:

so im trying to separate the twitter ids into a new file to avoid clutter on the main code file but i want to be able to actually know what the heck each id is so i need to keep the comments in.

iv tried a few ways to get rid of this with regex but the best iv done is just print them :/

heres the code

for line in open("userids.txt"):
    lin=re.sub(r'(?m)^ *#.*n?', '', line)
    li=re.search(r'?!#(w+)', lin)
    print(li)

the re.sub finds the line as a WHOLE but i want to preferably just ignore the comment entirely in one line rather than 2 like im trying here. i have tried so many different ways iv found on the internet and none work. this is the only code that even prints back the line.

format in the .txt file is

Twitterid #Twitterhandle

but i would like it to just be

Twitterid

i managed to get this working but the code is probably longer than it needs to be and the regex is more than likely unneeded in this case.

heres the code i used instead that returns JUST the twitter id for each line and also ignores comment lines.

        lin=re.sub(r'(?m)^ *#.*n?', '', line)
        clin=lin.strip()
        cleanlin=clin.split("#",1)
        id=cleanlin[0]
        print(id)