Link to home
Start Free TrialLog in
Avatar of potworny
potwornyFlag for Poland

asked on

Word delimiters? preg_match PHP

Hi there...

I am going to kill myself with a spoon in a minute...

I'd like to match string that begin with the word "ball":

I tried the following:
/\bball/im = no luck
/\bball\b/im = no luck
/ball/ = positive
I'd like this to match as follows
 
Ball is red. = match
Balls are red = match
RedBall is red = no match

Open in new window

Avatar of dvz-
dvz-
Flag of United States of America image

try

/^ball.*/
Avatar of potworny

ASKER

And what about ball in the following sentences? :)



This is a ball that is red. = match
I have a lot of balling to do. = match

Open in new window

Avatar of Terry Woods
/\bball/im
is correct - can you post your code, and maybe I can find a problem with it?
hrm...

that's odd.

$regex = '/^[bB]all.*/';

is saying to match 'ball' as the first chars of the string, and any other non new-line character after (.*).
The database contains:

/\bball/i

$query = "SELECT blackword_pattern FROM tbl_blackwords";
 
$countRows = $db->query($query);
while( $countRow = $db->fetch_array($countRows)){
      if( preg_match($countRow['blackword_pattern'], $string) ) return true; # found something
}
 
return false; #found nothing

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I made a stupid mistake. Yes.
The database contains "/\bball/im"
There should be "/\\bball/im"
(double backslash)

Thank you very much for your help guys. You saved one life :)