A. 求高手支招:php正则表达式修正css路径问题
preg_replace('/<link(.*?)href=\"(.*?(?:\.css))\"/','<link${1}href=\"theme/$path/${2}\"',$source).
link 和href之间的字符串要保留,同时将css文件路径这块拼凑一下。你写的,就默认link和href之间是一个空格。.*?代表任意字符。?:\.css代表以.css结尾。
B. php正则表达式提取CSS文件中所有background-position值并乘以1.5倍
<?php
$file = '需要请求的数据'
$data=file_get_contents($file);
preg_match_all('/background[^;]+;/', $data, $matches); //获得background的所有信息
print_r($matches);
$count = count($matches[0]);
for ($i=0; $i <$count ; $i++) {
preg_match_all('/[-0-9]+px/', $matches[0][$i],$ab ); //获得 x ,y
if ($ab[0][0]) {
$x[] = intval($ab[0][0])*1.5; //只要x的值
}
}
print_r($x);
?>
看看是不是你想要的
C. 如何用正则表达式,删除html里面的 css js
在DW里查找:<style>[^"]*</style>,替换为空,查找:style="[^"]*",替换为空。查找:<script>[^"]*</script>替换为空,就可以了。
D. 如何用正则表达式提取CSS中的图片路径
var str="NavBar{width:888px; height:35px; float:left;padding-left:62px; margin-top:1px; background:url(images/menu_bj.jpg) repeat-x; line-height:35px; font-size:12px;}.me{width:100px; height:35px; float:left; color:#FFFFFF; font-weight:bold; background:url(images/menu_homebj.jpg) repeat-x;}"
var arr = str.match(/url\(.+?\)/ig);
for(var i =0; i<arr.length; i++)
{
document.write(arr[i].replace("url(","").replace(")","") + "<br />");
}
E. 求过滤html标签和CSS样式表的正则表达式!
先过滤样式表之后再过滤html标签
过滤样式表用
<STYLE>[/s/S]*<\/STYLE>
然后再用<.[^>]*>过滤其他标签HTML
F. asp.net过滤过滤字符串,求正则表达式,style=“ 任意css样式 ”过滤掉
/style="[^"]*"/
这是正则,把他铺货到的替换成空就好了。
G. 求一个匹配CSS属性的正则表达式
/[^-]+(width[^;]+;)/g;
测试代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>
<body>
<script language="javascript">
<!--
str ="width : 697px;width : 693px;width:694px;width : 695px;width : 696px; border:1px solid #ccc; border-width:3px;"
re = /[^-]+(width[^;]+;)/g;
alert(str.match(re));
//-->
</script>
</body>
</html>
H. 求获取css样式的js正则表达式
vartestContent='.class1{color:red}.class2{color:blue}';
functiongetCss(className){
varreStr='.'+className+'[s]*{[^}]+?}';
varre=newRegExp(reStr,"gi");
returntestContent.match(re);
}
alert(getCss('class1'));
alert(getCss('class2'));
I. CSS背景图片的正则表达式怎么写
比如url(images/nan_bg_o.jpg)这是背景图的css写法,它的正则表达式如下
VBScript codes=".x{background:url(images/nan_bg_o.jpg);}.xx{}.xxx{background: URL(images/nan_bg_oxx.jpg) ;}"
set rx=new RegExp
rx.IgnoreCase=true
rx.Global=true
rx.Pattern="url\s*\(([^\)]+)\)"
set mc=rx.Execute(s)
for each m in mc
response.Write "<pre>"&m.submatches(0)&"</pre>"
next
set rx=nothing
J. 如何检测SQL注入和CSS攻击漏洞
对于他们的攻击,主要是通过使用正则表达式来做输入检测:
检测SQL meta-characters的正则表达式 :/(\%27)|(’)|(--)|(\%23)|(#)/ix
解释:我 们首先检查单引号等值的hex,单引号本身或者双重扩折号。
修正检测SQL meta-characters的正则表达式: /((\%3D)|(=))[^ ]*((\%27)|(’)|(--)|(\%3B)|(:))/i
解释: 这个规则首先留意 = 号或它的hex值(%3D),然后考虑零个或多个除换行符以外的任意字符,最后检测单引号,双重破折号或分号。
典型的 SQL 注入攻击的正则表达式: /w*((\%27)|(’))((\%6F)|o|(\%4F))((\%72)|r|(\%52))/ix
解释:
w* - 零个或多个字符或者下划线。
(\%27)|’ - 单引号或它的hex等值。
(\%6 F)|o|(\%4 F))((\%72)|r|-(\%52) -‘or’的大小写以及它的hex等值
检测SQL注入,UNION查询关键字的正则表达式: /((\%27)|(’))union/ix
(\%27)|(’) - 单引号和它的hex等值
union - union关键字
可以同样为其他SQL查询定制表达式,如 >select, insert, update, delete, drop, 等等.
检测MS SQL Server SQL注入攻击的正则表达式: /exec(s|+)+(s|x)pw+/ix
exec - 请求执行储存或扩展储存过程的关键字
(s|+)+ - 一个或多个的空白或它们的http等值编码
(s|x) p- ‘sp’或‘xp’字母用来辨认储存或扩展储存过程
w+ - 一个或多个字符或下划线来匹配过程的名称
CSS的检测也主要是正则表达式:
一般 CSS 攻击的正则表达式: /((\%3C)|<)((\%2F)|/)*[a-z0-9\%]+((\%3E)|>)/ix
解释:
((\%3C)|<) -检查<和它hex等值
((\%2F)|/)*-结束标签/或它的 hex等值
[a-z0-9\%]+ -检查标签里的字母或它hex等值
((\%3E)|>) -检查>或它的hex等值
"<img src" CSS 攻击正则表达式: /((\%3C)|<)((\%69)|i|(\%49))((\%6D)|m|(\%4D))((\%67)|g|(\%47))[^ ]+((\%3E)|>)/I
解释:
(\%3 C)|<) -<或它的hex等值
(\%69)|i|(\%49))((\%6D)|m|(\%4D))((\%67)|g|(\%47) -’img’字母或它的大小写hex等值的变化组合
[^ ]+ -除了换行符以外的任何跟随<img的字符
(\%3E)|>) ->或它的hex等值
CSS 攻击的极端的正则表达式 : /((\%3C)|<)[^ ]+((\%3E)|>)/I
解释:
这个规则简单寻找<+除换行符外的任何字符+>。由于你的web服务器和web应用程序的构架,这个规则可能产生一些错误。但它能保证捉住任何CCS或者类似CSS的攻击。