2017-02-20 6 views
2

コメント私が試したコードは、Pythonプログラムは、ここで

from re import * 


commentStart = compile('/\*') 
commentEnd = compile('\*/') 
singleComment = compile('//') 
quotes = compile('".*"') 

def readComment(line): 

    while(line): 
     if(commentEnd.match(line)): 
      return 
     line = input() 

line=input() 

while(line): 
    if(quotes.match(line)): 
     print(line) 
     line = input() 
     continue 

    elif(commentStart.match(line)): 

     readComment(line) 
     line=input() 
     continue 

    elif(singleComment.match(line)): 
     line=input() 
     continue 

    else: 
     print(line) 

    line=input() 

である私は、単一の行のコメントを削除することができるよしかし、私は、複数行のコメントに問題があります。

サンプル入力:

abcd 
//blah 
efg 
/*blah 
blah 
blah*/ 
hij 

マイ出力:

abcd 
efg 

予想される出力:

abcd 
efg 
hij 

私はミスを犯してきたところを指摘してください。ありがとうございました。

+1

あなたが回答を受け取った場合は、それを受け入れたことを示す必要があります。 –

答えて

4

この1:)あなたはどこにでも文字列に一致するものを検索したい場合は、

検索を使用します。docsから

commentEnd.search(line) 

commentEnd.match(line) 

があるべき代わりに

+0

ありがとう!それは今働いている。 – coder123

関連する問題