Jump to content


Regex pattern for sentence with word in

  • Please log in to reply
1 reply to this topic

#1 BRUm

  • Members
  • PipPip
  • Member
  • 28 posts

Posted 27 August 2006 - 09:31 AM


I'm currently coding a search engine, and everything seems to be going smoothly, until I reach regular expressions -_- (I hate them so much..). So far, the script can crawl a site from an array, and grab a sentence with the keywords. However, it's a bit messy, and I wondered if someone would be so kind as to show a pattern that would do it properly.

Basically, I need a pattern that matches a sentence with letters and numbers only (to filter out HTML) and with the sentence must have this in:

Here's the code I'm using at the moment:
I must say it's not too good.

Any help greatly appreciated,


#2 effigy

  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 28 August 2006 - 01:27 PM

if ( strstr($string, $pieces[0]) && preg_match('/^[A-Za-z0-9 .]$/', $string) ) { ... }

Regexp | Unicode Article | Letter Database

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users