忽略单词中的特定模式

Neglect specific pattern from word

我有单词(每个单词)从 :(冒号)开始,然后是数字,然后是任何内容

Example1:
word --> :129]]
output --> ]

Example2:
word --> :20]sometext]
output --> sometext]

我建议您使用 \K anchor,它会在最后打印时丢弃先前匹配的字符。 \K 将文本匹配到整个正则表达式匹配之外。

:\d+]\K.*

DEMO

$re = "~:\d+]\K.*~m";
$str = ":20]sometext]";
preg_match_all($re, $str, $matches);

i want simply negate that pattern from word, what is a regular expression for that?

我想你想在说否定时删除它。所以使用 /:\d+\]/g 并替换为空字符串。

可以使用 preg_replace

$a=':20]sometext]';
$a=preg_replace("/:\d+\]/","",$a);