Removing the comments from a string

后端 未结 2 1225
青春惊慌失措
青春惊慌失措 2021-01-21 02:45

I\'d like to do a function which gets a string and in case it has inline comments it removes it.

public class sample {

    public static void main(String[] arg         


        
2条回答
  •  渐次进展
    2021-01-21 03:26

    replaceAll("((/\\*)[^/]+(\\*/))|(//.*)", "")
    

    This will remove single line, multi-line or doc comments.

    The JavaScript compatible regex is ((/\*)[^/]+(\*/))|(//.*), which you can try with regexpal.com.

提交回复
热议问题