johnnyk Posted February 26, 2006 Share Posted February 26, 2006 /<p>((A |An |The )?)<b>Theodore Roosevelt<\/b>.[^\.]*(\.|\?|!)/iI'm newish at regex, so I can't figure this out out. The above regex basically matches up until it finds punctuation. For example, the following would be a match:<p><b>Theodore Roosevent</b> text text text.BUT, I want it to ignore certain punctiation, for example the period after Jr., so that it would be able to match<p><b>Theodore Roosevent</b> (Theodore Roosevelt Jr.) is a really cool guy.I would want it to ignore the . after Jr and go all the way up to the end of the sentence. I tried a bunch of things out but couldn't figure it out. Any help would be mucho appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/3617-regex/ Share on other sites More sharing options...
wickning1 Posted February 26, 2006 Share Posted February 26, 2006 That's too much logic to be automatic. How is it supposed to discern between an abbreviation and the end of a sentence? Regexes are powerful but they can't read English. You could add in some things to ignore, like "Jr.", but your regex would have to keep growing as you add more.example:/<p>((A |An |The )?)<b>Theodore Roosevelt<\/b>([^\.]|Jr\.)*(\.|\?|!)/i Quote Link to comment https://forums.phpfreaks.com/topic/3617-regex/#findComment-12545 Share on other sites More sharing options...
johnnyk Posted February 26, 2006 Author Share Posted February 26, 2006 Edit: Doesn't work. It looked like it would, don't know why it doesnt.Edit dos: I got it to work with$pattern = "/<p>((A |An |The )?)<b>$word<\/b> ((.[^\.]*)?(Jr\.)?(.[^\.]*))(\.|\?|!)/i";but did I do more than I had to?Edit 3: The above works, but also continues on to find second period even if Jr. isn't found. Quote Link to comment https://forums.phpfreaks.com/topic/3617-regex/#findComment-12587 Share on other sites More sharing options...
wickning1 Posted February 26, 2006 Share Posted February 26, 2006 /<p>((A |An |The )?)<b>Theodore Roosevelt<\/b>([^\.]*Jr\.)?[^\.]*(\.|\?|!)/i Quote Link to comment https://forums.phpfreaks.com/topic/3617-regex/#findComment-12609 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.