PHP preg_replace用于特定字符

时间:2019-02-12 11:38:28

标签: php regex preg-replace

我的数组中有多个字符串:

test/01-about-us/01-some-different-title
test/01-about-us/02-some-12345-title
test/01-about-us/03-12345-title
test/02-contact-us/01-foo
test/02-contact-us/02-bar
test/02-contact-us/02-foo-bar

做什么:
如果字符串包含每个正斜杠和第一个连字符之间的数字 删除数字和连字符

必填输出:

test/about-us/some-different-title
test/about-us/some-12345-title
test/about-us/12345-title
test/contact-us/foo
test/contact-us/bar
test/contact-us/foo-bar

哪种正则表达式适合呢?

1 个答案:

答案 0 :(得分:0)

#/\d+-#替换为/。 …                     –Niet the Dark Absol