不包含用
(?!pattern) 负向预查,在任何不匹配Negative lookahead matches the search string at any point where a string not matching pattern 的字符串开始处匹配查找字符串。这是一个非获取匹配,也就是说,该匹配不需要获取供以后使用。例如'Windows (?!95|98|NT|2000)' 能匹配 "Windows 3.1" 中的 "Windows",但不能匹配 "Windows 2000" 中的 "Windows"。预查不消耗字符,也就是说,在一个匹配发生后,在最后一次匹配之后立即开始下一次匹配的搜索,而不是从包含预查的字符之后开始
所以你例子可写成:
<script>
var str="[IMG=http://www.ssadda.com/admin/editor/upload/image/200241319594.jpg align=left]测试[/IMG]和[IMG=upload/image/200241319594.jpg align=left]测试[/IMG]"
var reg=/\[IMG=(?!http:\/\/)([^\s]+)\salign=(\w+)\]([^\[]+)\[\/IMG\]/gi
if(arr=str.match(reg)){
for(i=0;i<arr.length;i++)
alert(arr[i]+"\n中的链接是相对链接")
}
</script>
...全文
966打赏收藏
to huolx (飞云) :进来,你要的一个正则表达式的写法。
引用huolx (飞云) 说的 http://www.csdn.net/expert/Topicview1.asp?id=749865 我只知道正则表达式中不包含某些字符用[^xxx],匹配不包含某个字符串怎么写 不包含用 (?!pattern) 负向预查,在任何不匹配Negative lookahead matches the search string at any point where a string not matching pattern 的字符串开始处匹配查找字符串。这是一个非获