RegExp()在CSS中删除注释? [英] RegExp() to strip comments in CSS?

查看:54
本文介绍了RegExp()在CSS中删除注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我不是RegExp()的专家,虽然我确实使用它。

我遇到的问题是我要删除注释一个CSS

文件使用RegExp()


原因是我正在加载和解析来模拟javscript

访问Opera中的样式表。我以为自己已经舔了舔,直到网址(''')中的
''/''字符绊倒了我


下面是一个测试案例。我尝试了很多东西。但是,如果我不能确定一个干净的RegExp(),我将不得不这样做。

老派。有什么想法吗?

/ *

**多行评论

* /


/ *单行评论* /

..tester {

background:url(''http://www.somewhere.com/Images/space.jpg' ');

border-top:1px纯黑色;

border-bottom:1px纯黑色;

border-right:1px纯黑色;

border-left:1px纯黑色;

}

-

- 。

- =<> Clue博士(AKA Ian A. Storms)<> = - C ++,HTML / CSS,Javascript,TCP ......

- `


I''m not really an expert with RegExp() , although I do use it.
The problem I have is that I want to strip comments out of a CSS
file using RegExp()

The reason is that I''m loading and parsing to simulate javscript
access to stylesheets in Opera. I thought I had it licked untill the
''/'' characters in url('''') tripped me up

Below is a test case. I''ve tried many things. but if I can''t
figure out a nice clean RegExp(), I''m going to have to do it
old-school. Any thoughts?
/*
** A multi-line comment
*/

/* a single line comment */
..tester {
background:url(''http://www.somewhere.com/Images/space.jpg'');
border-top :1px solid black;
border-bottom :1px solid black;
border-right :1px solid black;
border-left :1px solid black;
}
--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML/CSS,Javascript,TCP ...
--`

推荐答案

Clue博士于2005年9月9日在comp.lang.javascript中写道
Dr Clue wrote on 09 sep 2005 in comp.lang.javascript:

我'虽然我确实使用它,但我并不是RegExp()的专家。
我遇到的问题是我想使用RegExp()来删除CSS
文件中的注释
<原因是我正在加载和解析模拟javscript
访问Opera中的样式表。我以为我舔了它直到url(''')中的
'/''字符绊倒了我

下面是一个测试案例。我尝试了很多东西。但是,如果我不能找到一个干净的RegExp(),我将不得不这样做
老派。有什么想法吗?

/ *
**多行评论
* /

/ *单行评论* /

I''m not really an expert with RegExp() , although I do use it.
The problem I have is that I want to strip comments out of a CSS
file using RegExp()

The reason is that I''m loading and parsing to simulate javscript
access to stylesheets in Opera. I thought I had it licked untill the
''/'' characters in url('''') tripped me up

Below is a test case. I''ve tried many things. but if I can''t
figure out a nice clean RegExp(), I''m going to have to do it
old-school. Any thoughts?
/*
** A multi-line comment
*/

/* a single line comment */



str =''aaa / * qqq * / aaa''


str = str.replace(/ \ / \ * [\ s \ S] *?(\ * \ /)/,'''')


alert(str)

str =''aaa / * \ n qqq \ n * / aaa''


str = str.replace(/ \ / \ * [\\\ S] *?( \ * \ /)/,'''')


警报(str)


IE6测试


-

Evertjan。

荷兰。

(用我的电子邮件中的点替换所有十字架)


str = ''aaa /* qqq*/ aaa''

str = str.replace(/\/\*[\s\S]*?(\*\/)/,'''')

alert(str)
str = ''aaa /* \n qqq \n */ aaa''

str = str.replace(/\/\*[\s\S]*?(\*\/)/,'''')

alert(str)

IE6 tested

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)


谢谢你回复Evertjan

我试过你的例子,它确实适用于

小测试案件,但看起来测试案例很害羞

因此,实际上有问题的文件我正在尝试

剥离评论,因为它不公平很好。

/ *文件:jsMENUlib.css

**作者:Clue博士(AKA Ian A.风暴)

**描述:这是您控制

**菜单及其menupads的一般外观。

* /


/ *菜单面板的正常显示外观,而不是

菜单垫

* /

..jsMenuPanel {

background:url(''http://www.drclue.net/Assets/Images/paper/space.jpg'');

border-top:1px solid black;

border-bottom:1px纯黑色;

border-right:1px纯黑色;

border-left:1px纯黑色;

}

/ *未突出显示的菜单键的正常显示外观

* /

..jsMenupadLO {

字体大小:12pt;

颜色:#ffffcc;

背景颜色:透明;

显示:块;

边框:1px纯黑色;

}

/ *高光d用鼠标在它上面显示一个垫的外观

* /

..jsMenupadHI {

background:url(''http:/ /www.drclue.net/Assets/Images/paper/spaceLT.jpg'');

字体大小:12pt;

颜色:#ffff00;

/ * background-color:#99aabb;

* /

display:block;

border:1px solid black;

}

/ *未突出显示的菜单键的禁用外观(无XML操作

值)。* /

..jsMenupadGRY {

/ *填充:2px;

* /

字体大小:12pt;

颜色:#999999;

背景颜色:#99aabb;

显示:块;

边框:1px纯黑色;

}


-

- 。

- =<> Clue博士(AKA Ian A. Storms)<> = - C ++,HTML / CSS,Javascript,TCP ......

- `
Thankyou for responding Evertjan
I tried your example , and it did indeed work with the
little test case, but it appears the test case was shy of the mark
so heres the actual file in question that I''m attempting to
strip the comments from, as it did not fair so well.
/* File : jsMENUlib.css
** Author : Dr. Clue ( A.K.A. Ian A. Storms )
** Description : This is where you control the general appearance of
** the menus, and their menupads.
*/

/* The normal display appearance of the menu panel as opposed to the
menu pads
*/
..jsMenuPanel {
background :url(''http://www.drclue.net/Assets/Images/paper/space.jpg'');
border-top :1px solid black;
border-bottom :1px solid black;
border-right :1px solid black;
border-left :1px solid black;
}
/* The normal display appearance of an un-highlighted menu pad
*/
..jsMenupadLO {
font-size :12pt ;
color :#ffffcc ;
background-color :transparent ;
display :block ;
border :1px solid black;
}
/* The highlighted display appearance of a pad with the mouse over it
*/
..jsMenupadHI {
background :url(''http://www.drclue.net/Assets/Images/paper/spaceLT.jpg'');
font-size :12pt ;
color :#ffff00 ;
/* background-color :#99aabb ;
*/
display :block ;
border :1px solid black;
}
/* The disabled appearance of an un-highlighted menu pad ( no XML Action
value).*/
..jsMenupadGRY {
/* padding :2px ;
*/
font-size :12pt ;
color :#999999 ;
background-color :#99aabb ;
display :block ;
border :1px solid black;
}

--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML/CSS,Javascript,TCP ...
--`


Clue博士于2005年9月9日在comp.lang.javascript中写道
Dr Clue wrote on 09 sep 2005 in comp.lang.javascript:
谢谢你回复Evertjan
我试过你的例子,


这是usenet。其他人正在阅读蚂蚁,不想在最后一个帖子中搜索

,所以网络礼节说:总是引用相关部分

发布

并且它确实与
小测试用例一起工作,但看起来测试用例很害羞
所以这个实际的文件是我试图用的那个
剥离评论,


的确,我告诉你正则表达式只适用于字符串而不是文件,所以

首先要做的就是你要做的事情看看你将文件转换成字符串的方式,Ian。你正在使用什么系统,因为在转换为

字符串时可能无法识别

换行符。

as它不太公平。


这是相当危险的。我不知道该怎么回答。

请详细说明这美化不起作用。


/ *文件: jsMENUlib.css
[...]
Thankyou for responding Evertjan
I tried your example,
This is usenet. Other peaple are reading to ant don''t want to search for
the last posting, so netiquette says: always quote relevant part that
posting
and it did indeed work with the
little test case, but it appears the test case was shy of the mark
so heres the actual file in question that I''m attempting to
strip the comments from,
Indeed, I dit tell you regex only works on strings, not on files, so the
first thing you would have to do is look into the way you convert your file
to a string, Ian. And what system you are you are using, since perhaps the
newline representation could not be recognized in the conversion to a
string.
as it did not fair so well.
This is rather criptic. I don''t know what to answer on that.
Please elaborate on this beautified "doesn''t work".


/* File : jsMENUlib.css
[...]




因此,在您的测试阶段,请将您的js文件的相关部分包含在
$ b中$ b string litteral。


-

Evertjan。

荷兰。

(替换所有在我的电子邮件地址中都有点点缀)



So in your testphase, please include relevant part of your js-file as a
string litteral.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)


这篇关于RegExp()在CSS中删除注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆