LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Matching with SQL (https://www.linuxquestions.org/questions/programming-9/matching-with-sql-266827/)

Ephracis 12-15-2004 05:55 PM

Matching with SQL
 
I have a table called bannedNicks that contains only one column so far called "banned" with the type varchar(50).

Now in my C++ program I use this table to check if a nick is legal by sending a query like:
Code:

SELECT count(banned) FROM bannedNicks WHERE banned="<nick>";
But I would like to be able to have nicks in the database that looks like cr*, moist?rize and ^dud[e3]$. Yeah, I want to use regexp but if I have something like that how can I make a question that would find the post with ^dud[e3]$ when I have the nick dude or dud3? Banning both nicks with just one post using regexp.

Tinkster 12-15-2004 06:34 PM

Code:

SELECT count(banned) FROM bannedNicks WHERE banned LIKE '%<chunk>%';
should do the trick ... that's not quite regex matching but will
cover quite a few not too unusual nicks ;)

If that doesn't QUITE do what you want you'll need to load
the result table into some C++ data-structure and run patter-
matching against that e.g. vector of strings ...



Cheers,
Tink

Ephracis 12-15-2004 06:38 PM

Yes I was aware of the "LIKE" and "%" but the thing is that that does "the other way around". It's the post in the database that is the pattern and the nick is what should be matched. :/

csfalcon 12-15-2004 10:41 PM

so the database contains the regular expressions and you want to do the matching in C++?

Ephracis 12-16-2004 05:09 AM

Quote:

Originally posted by csfalcon
so the database contains the regular expressions and you want to do the matching in C++?
Yes but I use MySQL so I could use it in SQL and/or C++. My first thought was to check every row in the table and use the regexp in the table to try to match the nick. The main problem was that it could be inefficient if the database would grow big.


All times are GMT -5. The time now is 02:23 AM.