1
var path1 = 'catalog/view/theme/default/image/flags/usa.png';

var path2 = '../catalog/view/theme/default/image/flags/usa.png';

var path3 =  '/catalog/view/theme/default/image/flags/usa.png';

var path4 =  '__catalog/view/theme/default/image/flags/usa.png';

var path5 =  '@catalog/view/theme/default/image/flags/usa.png';

var path6 =  '%catalog/view/theme/default/image/flags/usa.png';

var path7 =  '?catalog/view/theme/default/image/flags/usa.png';

什么是正则表达式来确保和前缀 / 到一个 url 字符串的开头结果应该是 /catalog/view/theme/default/image/flags/usa.png

4

4 回答 4

0

尝试以下操作:

       '/' + path2.match(/catalog.*/)
于 2012-04-26T19:35:38.723 回答
0

正则表达式

/^\/.*$/

将匹配一个开始的斜线。

/^[^\/].*$/

将匹配一个没有斜杠的字符串。

于 2012-04-26T19:36:57.433 回答
0

简短的回答:

var patern =/[a-z].+$/gi;
var use = '/'+'__catalog/view/theme/default/image/flags/usa.png'.match(/[a-z].+$/gi)[0];
//use === "/catalog/view/theme/default/image/flags/usa.png"

给你

于 2012-04-26T19:37:26.770 回答
0

您可以使用

var url='/'+path2.match(/[a-z].*/gi); // use path1 to path7
console.log(url);​​ // Result is: /catalog/view/theme/default/image/flags/usa.png
于 2012-04-26T19:40:17.410 回答