potworny
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 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
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
/\bball/im
is correct - can you post your code, and maybe I can find a problem with it?
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 (.*).
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 (.*).
ASKER
The database contains:
/\bball/i
/\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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 :)
The database contains "/\bball/im"
There should be "/\\bball/im"
(double backslash)
Thank you very much for your help guys. You saved one life :)
/^ball.*/