Page 1 of 1

Need help with regular expression

Posted: Wed Nov 08, 2006 8:14 am
by amir
I am currently using on my php/Mysql db. The only problem is the expression is taking way to long to do the search of the db, even though the db is properly indexed. The expression finds an exact match in the Topic field which is what I wanted. However, the speed of search problem and the server load is a bigger problem. Here is the query with the regular expression.

Code: Select all

$query = "SELECT * FROM `View6` WHERE `Topic` REGEXP '[[:<:]]" .
 mysql_real_escape_string($SeeAlso) .
 "[[:>:]]' AND `Source` = $NNN OR (`Source` = $TTT) ORDER BY `Lnum` ASC";
Is there a way to change the regular expression above to find a white space before the

Code: Select all

$SeeAlso
variable if the

Code: Select all

$SeeAlso
variable is within a sentence or find the

Code: Select all

$SeeAlso
variable if the

Code: Select all

$SeeAlso
variable is the first word in the sentence. For example, if the user wants to find the word "fear" without the quotes, the regular expression would find...

fear
fearless
fearlessly
fearful
fearsome

...if these words appear at the beginning of a sentence or within a sentence.

Thank you in advance for any replies.

Posted: Wed Nov 08, 2006 9:26 am
by printf
Just use the left side boundary, meaning (find all $SeeAlso that start with $SeeAlso or that $SeeAlso is after (non-word character, NOT -> [^a-zA-Z_0-9])

Code: Select all

$query = "SELECT * FROM View6 WHERE Topic REGEXP '[[:<:]]" . mysql_real_escape_string ( $SeeAlso ) . "' AND Source = " . $NNN . " OR Source = " . $TTT . " ORDER BY Lnum ASC";
printf