So I'm new to python, (i wrote my first bit of code I it today) (I'm relitivly experienced in C, and decent in C++, Java and assember - if abit out of practice) I'm, making a program to automate the writing of some C code, (I'm writing to parse stigns into enumerations with the same name) C's handleing of stings is, well it's not that great. So some people have been nagging me to try python (actually they have been nagging me to makepython my primairy language)
I'm findin python kinda wierd, it's very loose.
anyway I made a function that is supposed to remove c syle /* COMMENT */ and //COMMENT from a string: He's the code:
def removeComments(string):
re.sub(re.compile("/\*.*?\*/",re.DOTALL ) ,"" ,string) # remove all occurance streamed comments (/*COMMENT */) from string
re.sub(re.compile("//.*?\n" ) ,"" ,string) # remove all occurance singleline comments (//COMMENT\n ) from string
It's been a while since i used RegEx too, and even then i'e only had to use it less than a dozen times before.
So I tryed this code out.
str="/* spam * spam */ eggs"
removeComments(str)
print str
And it apparently did nothing.
Any suggestions as to what I've done wrong?
Theres a saying i've heard acouple of times: If you have a problem and you try to solve it with RegEx you endup with two problems