Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从asp.net页面中删除javascript注释_Asp.net_Regex - Fatal编程技术网

从asp.net页面中删除javascript注释

从asp.net页面中删除javascript注释,asp.net,regex,Asp.net,Regex,假设我在我的aspx页面中编写javascript,如下所示 <script type="text/javascript"> function pop() { // test 1 /* test1 test2 test3 */ myfunc1(); myfunc1(); myfunc1(); } 函数pop(){ //测试1 /*测试1 测试2 测试3 */ myfunc1(); myfun

假设我在我的aspx页面中编写javascript,如下所示

<script type="text/javascript">
function pop() {
    // test 1

    /*  test1
        test2
        test3
    */
     myfunc1();
     myfunc1();
     myfunc1();
}

函数pop(){
//测试1
/*测试1
测试2
测试3
*/
myfunc1();
myfunc1();
myfunc1();
}

现在在运行时,我想使用页面的regex-from-render方法从页面中删除所有javascript注释。告诉我我需要用什么正则表达式

protected override void Render(HtmlTextWriter writer)
    {
        using (HtmlTextWriter htmlwriter = new HtmlTextWriter(new System.IO.StringWriter()))
        {
            base.Render(htmlwriter);
            string html = htmlwriter.InnerWriter.ToString();

            if ((ConfigurationManager.AppSettings.Get("RemoveWhitespace") + string.Empty).Equals("true", StringComparison.OrdinalIgnoreCase))
            {

                // regex for removing html comment
                html = Regex.Replace(html, @"((<!-- )((?!<!-- ).)*( -->))(\r\n)*", String.Empty);
                // regex for removing line break & carriage return
                html = html.Replace(";\r\n", ";");
            }
            writer.Write(html.Trim());
        }
    }
受保护的覆盖无效渲染(HtmlTextWriter)
{
使用(HtmlTextWriter htmlwriter=new HtmlTextWriter(new System.IO.StringWriter()))
{
base.Render(htmlwriter);
字符串html=htmlwriter.InnerWriter.ToString();
if((ConfigurationManager.AppSettings.Get(“RemoveWhitespace”)+string.Empty).Equals(“true”,StringComparison.OrdinalIgnoreCase))
{
//用于删除html注释的正则表达式
html=Regex.Replace(html,@“(())(\r\n)*”,String.Empty);
//用于删除换行符和回车符的正则表达式
html=html.Replace(“;\r\n”,“;”);
}
writer.Write(html.Trim());
}
}
试试这个:

((\/\*[\s\S]+?\*\/)|(\/\/.+))

到目前为止,什么还在工作,什么还没有工作?现在一切都还在工作,但如果我在aspx页面中有javascript单行或多行注释,就会出错。我还需要从页面中删除javascript单行和多行注释(如果存在)。因此,plzz告诉我需要在代码中添加什么,以便从页面中删除javascript单行和多行注释(如果存在)。thanksit提示有效,但很少有代码行被扭曲。该代码如下所示。