我有一个类似以下的网址。
http:// myipaddress / folder1 / folder2 / themes / index.html
有谁知道最好的方法总是使用javscript字符串操作reg exp技术来始终掌握以前的内容,而不包括/ themes /。第一位通常与/themes/index.html不同,后者是静态的
您可以使用前瞻性获取之前的所有文本/themes
,
> var str = 'http:// myipaddress/folder1/folder2/themes/index.html';
undefined
> var patt1 = /^.*(?=\/themes)/gi;
undefined
> var result = str.match(patt1);
undefined
> console.log(result);
[ 'http:// myipaddress/folder1/folder2' ]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句