开发者

Matching a nonquoted string

开发者 https://www.devze.com 2023-01-09 02:17 出处:网络
I\'m trying to work with regexes in PHP on my school\'s news site (running WordPress). The idea is, whenever someone saves a post, all instances of \"Regis\" (without \'Jesuit\' at the end) are replac

I'm trying to work with regexes in PHP on my school's news site (running WordPress). The idea is, whenever someone saves a post, all instances of "Regis" (without 'Jesuit' at the end) are replaced with "Regis Jesuit." (I go to Regis Jesuit High School, and they're picky about their branding). Overall this works fine with the following case-insensitive regex:

开发者_开发知识库
/regis(?! jesuit)/i

How would I modify this regex so it doesn't match if it finds the string "Regis" or 'Regis' (in single or double quotes)? (or even "I go to Regis High School" quoted as well)? The idea here is to change it where necessary, but to keep it the same in direct quotes in people's stories so we don't change people's quotes.

Thanks! Morgan


Based on the comments to the question, perhaps a solution would be to stick with your current regex, but use it as a client-side JavaScript warning only.

So, if the text entered matches "regis" not followed by " jesuit" then before the user submits simply displays a message saying "make sure you've correctly branded us", but which doesn't automatically change anything - basically leaving the language complexity stuff to the brain of a human who can (hopefully) understand it. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消