匹配括号内的所有子字符串,但那些以列入黑名单的单词开头 [英] Matching all substrings inside parentheses but those starting with blacklisted word

查看:26
本文介绍了匹配括号内的所有子字符串,但那些以列入黑名单的单词开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 PHP 中,使用 preg_replace,如何编写正则表达式,以便括号中的除The"之外的任何短语 &前面有空格被删除.例如,

In PHP, using preg_replace, how do I write a regular expression so that any phrase, except "The," in parenthesis & preceded by a space is deleted. E.g.,

Concordia University (Anything But The) => Concordia University
American University (The) => American University (The)

推荐答案

preg_replace 是否支持否定前瞻?如果是这样,你可以做这样的事情......

Does preg_replace support negative lookaheads? If so you can do something like this...

\((?!The\)).*?\)

这篇关于匹配括号内的所有子字符串,但那些以列入黑名单的单词开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆