- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个字符串,一个文件路径,类似
$string = "customer-service/tweep/cs/gsergsergrs/2017-20190Course-Schedule.pdf"
我想用 3 个破折号替换反斜杠之前的所有字符,以便返回:
$string = ---/---/---/---/2017-20190Course-Schedule.pdf
我试过使用这个 preg_replace 模式,但它返回 ---/2017-20190Course-Schedule.pdf
preg_replace( "/(.+\/)+/", "---/", $string);
有什么方法可以在模式匹配的每个实例上运行替换?
最佳答案
你可以使用
preg_replace('~[^/]+/~', "---/", $string);
// => ---/---/---/---/2017-20190Course-Schedule.pdf
参见 PHP demo .
参见 regex demo here .详情:
[^/]+
- /
/
- 正斜杠。请注意,/
不必转义,因为使用了 ~
分隔符。 preg_replace
函数用替换模式 ---/
替换所有 非重叠事件,因此无需使用重复捕获组(如在最初的尝试中)。
关于php - 替换所有字符直到反斜杠n次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49543991/
我有一个右下角倾斜的元素,我必须在其上放置一个盒子阴影。有时倾斜的 Angular 被徽章覆盖 - 我的问题不适用,如果是这样的话: 这是信息框及其边 Angular 的 (s)css 部分(还有更多
是否可以在纯 html/css 中创建类似下面的内容? 我想做这个响应式和全 (100%) 宽度(最大左 Angular 100 像素,右边最小 50 像素,类似的东西)。 最佳答案 您可以通过转换(
如何在 fabricjs 文本中为文本提供渐变或斜 Angular 效果?? http://fabricjs.com/fabric-intro-part-2/ 这里给出了形状和所有示例,我将其与文本绑
我用过: http://apps.eky.hk/css-triangle-generator/ 为彼此对 Angular 放置的两个不等边三 Angular 形生成 css: 左下三 Angular
我是一名优秀的程序员,十分优秀!