简体   繁体   中英

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

This is the string I have. Script:

Select * from tablename()

/*

go

*/

My code looks like this

private string RemoveBetween(string editScript, char begin, char end)
{
   Regex regex = new Regex(string.Format("///.*?///", begin, end));
   return  regex.Replace(editScript, string.Empty);
}

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

AM unable to remove the text between /*----*/ .

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, "/\*", "\*/");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM