抱歉,这件事(但我是个大白鲨)
在js中,如何替换url字符串中的第一个文件夹。
伪码:
Replace at start of string: /any-amount-of-characters/ with nothing示例
$path = '/xyz/abc/';应导致
$path = 'abc/';谢谢!
发布于 2015-01-07 09:50:00
^\/[^/]*\/尝试this.Replace by empty string.See演示。
https://regex101.com/r/sH8aR8/15
var re = /^\/[^\/]*\//g;
var str = '/xyz/abc/';
var subst = '';
var result = str.replace(re, subst);发布于 2015-01-07 09:52:12
您需要使用^匹配字符串的开头。
$path = '/xyz/abc/';
$path = $path.replace(/^\/?[^\/]*\//, '');分解:
^ -字符串的开始\/? -可选的引导/ (如果需要的话移除? )[^\/]* -除/以外的任意数量的字符(如果必须至少有一个字符,则使用+而不是* )\/尾随/https://stackoverflow.com/questions/27816567
复制相似问题