views:

53

answers:

1

Hi- 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

+1  A: 

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. :)

Peter Boughton
I see where you're going with this. However, I think I discovered a better solution.Managing newsteams of high school guys is hard enough. We've tried the solution you suggested before and it hasn't worked too well. People call the school "Regis" but the school wants it branded as "Regis Jesuit." Still, no one listens.
integ3r
95% of the time our writers refer to Regis Jesuit as "Regis" too.The solution (in my opinion) is to use the same regex I had earlier, with one modification:/(?<!\[\[)regis(?! jesuit)(?!\]\])/iI've set it up so that people can enter "Regis" by itself ONLY if they enter it as "[[Regis]]" (the other 5% of the time). A filter changes it back to "Regis" when the post is displayed.I think this is the best solution because it doesn't eliminate the choice of just saying "Regis".
integ3r