簡體   English   中英

如何使用正則表達式刪除aspx頁面源代碼中的CSS類?

[英]How to remove CSS Class in aspx pages source codes using Regex?

我嘗試重新排列我的sorce文件,例如:從aspx頁面中刪除所有css樣式。 我有一個文件(C:/ file:mypage.aspx和30-40 aspx頁),如何在C#中使用Regex刪除CSS樣式鏈接等? 請我需要您的最大幫助,這很重要:)我嘗試將Winforms(.EXE)寫入羅馬CSS屬性

我想刪除下面的一切!


   <link href="../Styles/Interm.css" rel="stylesheet" type="text/css" />
<style type="text/css">

// ERASE EVERYTHING
  </style>
  class="PageHeader"
CssClass="style1"

 CssClass="MyCss",CssFilePath="/test/style.css",CssPostFix="Aqua"

我的代碼:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace RemoverTags
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           richTextBox1.Text = RemoveWhiteSpaceFromStylesheets(richTextBox1.Text);
        }

        public  string RemoveWhiteSpaceFromStylesheets(string body)
        {
            body = Regex.Replace(body, "type="+"\"text/css\"", "");

            body = Regex.Replace(body, @"[a-zA-Z]+#", "#");

            body = Regex.Replace(body, @"[\n\r]+\s*", string.Empty);

            body = Regex.Replace(body, @"\s+", " ");

            body = Regex.Replace(body, @"\s?([:,;{}])\s?", "$1");

            body = body.Replace(";}", "}");

            body = Regex.Replace(body, @"([\s:]0)(px|pt|%|em)", "$1");



            // Remove comments from CSS

            body = Regex.Replace(body, @"/\*[\d\D]*?\*/", string.Empty);


            Regex r1 = new Regex(@"<style >([A-Za-z0-9\-]+)</style>");
            Match match = r1.Match(body);
            string v = "";
              if (match.Success)
              {
                   v = match.Groups[1].Value;

              }
              body = Regex.Replace(body, v, string.Empty);
              body = Regex.Replace(body, @"<(style|\n)*?>", string.Empty);
              body = Regex.Replace(body, @"<(/style|\n)*?>", string.Empty);
            return body;

        }

    }
}

but not working...

使用Visual Studio查找工具(ctrl + shift + f),轉到“查找選項”,然后選擇正則表達式來替換所有樣式元素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM