Remove text in between delimiters in a string - regex? when the string has '/'

后端 未结 1 1827
野趣味
野趣味 2021-01-24 21:13

This is the string I have. Script:

Select * from tablename()

/*

go

*/

My code looks like this

private string RemoveBetween(s         


        
相关标签:
1条回答
  • 2021-01-24 21:45
    private string RemoveBetween(String editScript, String begin, String end)
    {
       return Regex.Replace(editScript,
                            String.Format("{0}.*?{1}", begin, end),
                            String.Empty,
                            RegexOptions.Singleline)
    }
    

    usage:

    editscript = RemoveBetween(editscript, "/", "/");
    

    I've changed your signature to use String, because you probably might want to call it like so (to remove SQL comment blocks):

    editscript = RemoveBetween(editscript, "/\*", "\*/");
    
    0 讨论(0)
提交回复
热议问题