locked
Regex remove comments RRS feed

  • Question

  • User-2132497554 posted

    Hi folks,

    I want to remove comments e.g

    # This is comment
    This is code1
    This is code2  # This is comment
    # This is comment
    This is code3
    This is code4 

    I want output like

    This is code1 
    This is code2 
    This is code3 
    This is code4 

    Here is regex as below:
    (\#.*)|[A-Za-z]\w+

    I am not sure how to exclude or something Not operator.
    Could you please help me to solve this problem?

    Thank you 

    Ref:
    https://regexr.com/




    Saturday, May 8, 2021 5:13 AM

All replies

  • User1535942433 posted

    Hi IamGuy84,

    Where do you write these codes? C#? If you want to know how to remove the comment lines, you could push other lines not comments into  a new array.

    I suggest you could post your codes to us.It will help us to solve your problems.

    Best regards,

    Yijing Sun

    Monday, May 10, 2021 6:07 AM