GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Tech REGEXP not working right? (https://gfy.com/showthread.php?t=1349422)

Publisher Bucks 10-25-2021 10:48 PM

REGEXP not working right?
 
This is what I am using:

Quote:

SELECT * FROM Recipe WHERE Category REGEXP '/(?=.*?(seafood))(?=.*?(lunch))/is' ORDER BY RAND() LIMIT 5;");
I want it to display the results for rows that contain both the words (any cAsE) 'seafood' AND 'lunch' in the Category column, it doesnt like my expression though for some reason, any pointers please?

I was under the impression i could use the following to do what I wanted:

Quote:

SELECT * FROM Recipe WHERE Category REGEXP '(?=.*seafood)(?=.*lunch)' ORDER BY RAND() LIMIT 5;");
But it doesnt seem to like that either :Oh crap

faperoni 10-26-2021 03:24 AM

Maybe LIKE works better for you

Code:

SELECT * FROM Recipe WHERE Category LIKE '%seafood%' OR Category LIKE '%lunch%' ORDER BY RAND() LIMIT 5;");
if the keyword is always at the end of the string you can also use

Code:

SELECT * FROM Recipe WHERE Category LIKE '%seafood' OR Category LIKE '%lunch' ORDER BY RAND() LIMIT 5;");
Maybe its better to extract these keywords and put them in a separate table? LIKE (or REGEXP) are "slow".

More pattern matching examples and options:
https://dev.mysql.com/doc/refman/8.0...-matching.html

k0nr4d 10-26-2021 07:11 AM

Faperoni is right, you should consider just using like. REGEXP is hard as fuck and if you are a beginner you simply aren't going to be able to grasp it just yet because people who have been coding for 20 years have issues with it.

sarettah 10-27-2021 05:26 PM

Quote:

Originally Posted by k0nr4d (Post 22928050)
Faperoni is right, you should consider just using like. REGEXP is hard as fuck and if you are a beginner you simply aren't going to be able to grasp it just yet because people who have been coding for 20 years have issues with it.

This ^^^^^

I've been slamming code for a hell of a long time and hate the fuck out of reguar expressions.

Like will do it for you most of the time. :thumbsup

.


All times are GMT -7. The time now is 08:09 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123