标签: php regex
我需要一些正则表达式来删除字符串开头的[和]以及中间的任何内容,所以:
[
]
[text]KeepThis应为KeepThis。
[text]KeepThis
KeepThis
我似乎无法理解如何做到这一点(自从我使用正则表达式以来很长时间:) :)
答案 0 :(得分:2)
$result = preg_replace( '/^\[.*?\]/', '', $string );
正则表达式从字符串的开头找到任意一对括号及其内容,并用空字符串替换它。