如何在PHP上用正则表达式替换文本?
我有一个类似“MASTER_teaching.NAME”的文本,所以想用空格或其他字符串替换*MASTER_teaching*。如何在regexphp上实现这一点如何在PHP上用正则表达式替换文本?,php,regex,Php,Regex,我有一个类似“MASTER_teaching.NAME”的文本,所以想用空格或其他字符串替换*MASTER_teaching*。如何在regexphp上实现这一点 *我对REGEX是个新手。谢谢如果只替换字符串而不是模式,可以使用str_replace使用正则表达式或简单字符串函数 $string = 'MASTER_LECTURE.NAME'; $string_replace = 'MASTER_LECTURE'; // Regular expression preg_replace('/
*我对REGEX是个新手。谢谢如果只替换字符串而不是模式,可以使用str_replace使用正则表达式或简单字符串函数
$string = 'MASTER_LECTURE.NAME';
$string_replace = 'MASTER_LECTURE';
// Regular expression
preg_replace('/'.preg_quote($string_replace).'/is', '', $string);
// String function
$string = str_replace($string_replace, '', $string);
您不需要公式。它只是str_replace($search,$replace,$subject)。如果它真的是一个单词而不是一种模式,你应该使用它,因为它很轻。我需要这个模式,因为单词将由dinamic.nice@delphist生成。你能告诉我什么时候word MASTER_讲座将取决于我们提交的字符串吗?