php中的正则表达式,选择部分之后的所有内容


Regex in php, select everything after a part

我有一个字符串,我只想要在'### - '之后的内容。

的例子:

1234 - This is a string with 100 characters

我想把这个去掉:This is a string with 100 characters

我已经试了几个小时了,但是我不能让它工作。我认为这段代码选择了数字和-符号:#^'d+ - #,但我想要字符串的完全相反的部分。

感谢帮助

你可以使用这个正则表达式:

~^'d+ - (.+)$~

并抓取已捕获组#1

或使用match reset 'K:

~^'d+ - 'K.+$~

RegEx演示

PS:您也可以像这样使用preg_replace中的尝试正则表达式:

$input = preg_replace('#^'d+ - #', '', $input);