/ Forside / Teknologi / Udvikling / SQL / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
SQL
#NavnPoint
pmbruun 1704
niller 962
fehaar 730
Interkril.. 701
ellebye 510
pawel 510
rpje 405
pete 350
gibson 320
10  smorch 260
Seraching for WHOLE words only with LIKE
Fra : Christian Borchgrevi~


Dato : 24-04-02 21:14

I want to such match "foo" in "foo bar", "bar foo", "bar foo bar", or "foo"
but not in "foobar" or "barfoo". I try this query:

"SELECT * FROM forumPosts WHERE (message LIKE
'(^|[^a-zA-Z])$sokSplitt[$i]([^a-zA-Z]|$)')"

It returns nothing.

Then if I use this one:

"SELECT * FROM forumPosts WHERE (message LIKE '%$sokSplitt[$i]%')"

I get every occurance of "foobar", "foo" etc, no matter if it is a single
word or part of a word.

Any suggestions on how to get a match for only complete words?

Thanks



 
 
Jens Gyldenkærne Cla~ (24-04-2002)
Kommentar
Fra : Jens Gyldenkærne Cla~


Dato : 24-04-02 22:30

"Christian Borchgrevink-Lund" <borchgrevink@yahoo.com> skrev:

> I want to such match "foo" in "foo bar", "bar foo", "bar foo
> bar", or "foo" but not in "foobar" or "barfoo". I try this
> query:

> "SELECT * FROM forumPosts WHERE (message LIKE
> '(^|[^a-zA-Z])$sokSplitt[$i]([^a-zA-Z]|$)')"

I am not sure how your database implements regex, but I doubt that
(^|[<pattern>]) will work. If \b (word boundary) is supported, you
should be able to use LIKE '\b$sokSplitt[$i]\b' - that's it.

Without regex'es you can do something like:

WHERE (' ' + message + ' ') LIKE '% $sokSplitt[$i] %'

It will match "foo" in "foo", "foo bar", "bar foo", and not match
"foobar" or "barfoo". However, it will also not match foo in
"foo.", "foo, bar", "foo!" etc.

Hope it helps.

--
Jens Gyldenkærne Clausen
MF (Medlem af Fiduso - www.fiduso.dk)

Søg
Reklame
Statistik
Spørgsmål : 177558
Tips : 31968
Nyheder : 719565
Indlæg : 6408927
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste