November 6th, 2000, 02:59 PM
Currently i am using the following to select records where the "username" field doesn't start with a letter.
"SELECT * FROM users WHERE username NOT RLIKE '[A-Za-z].*'"
However, it doesn't return records that start with certain symbols. Am i doing somthing stupid?
November 6th, 2000, 05:44 PM
Yup. You need to anchor your regexp to the start of the sentence. The following should do the trick:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
SELECT * FROM users WHERE username NOT RLIKE '^[A-Za-z]'
Just remember, when you want to match something from the start of a line, begin your regexp with the ^ character, and when you want to match something to the end of the line, end it with the $ character.
One note on this, use as little description as possible to do your regexp accurately. For example, don't write a regexp of '^[a-zA-Z].*$' when you mean '^[a-zA-Z]' -- they match exactly the same set of literal strings, but the first will be much slower as it will examine the whole string for no reason (it slurps in and examines everything from start-of-line to end-of-line).
November 7th, 2000, 03:42 AM