# Regualr Expression for C comments [duplicate]

I hope you can help me right now, I am working on lexical analyzer for C language, I am bit confuse bout the regular expression of C style comments. a regex which can handle both single and multiline comments.

• If this were not already a duplicate, I'd ask: what have you tried and where did you get stuck? – Raphael Nov 4 '14 at 16:32
• Could you be more precise? What is your problem ? – babou Nov 4 '14 at 16:39
• @Raphael there are so many answers to them and none of them is working for me, i want a single regex which can handle both single and multiline comments. – Noor Nov 4 '14 at 16:47
• @babou my problem is I have to submit assignment withing 2 hrs! well joke apart my regex is not handling both single and multiline comments in C, is this regex alright = (/*.*?*/)|//.*?\n " – Noor Nov 4 '14 at 16:52
• @Noor Your homework is your own to do, otherwise you'll learn little to nothing. That said, if you have regular expressions (!= regex, btw) $r_1$ and $r_2$ for both types, joining them like $r_1 + r_2$ should do the trick. (What do you match; the whole text? Lines?) – Raphael Nov 4 '14 at 18:28