If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > MYSQL REGEXP REPLACE - Proving very difficult...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-13-09, 11:17
avera avera is offline
Registered User
 
Join Date: Apr 2009
Posts: 3
MYSQL REGEXP REPLACE - Proving very difficult...

Hi Everyone,

So - I have the following problem - here's my query:

Code:
SELECT
	CONCAT('C-', `idcategories`, '-', LOWER(REPLACE(categoryname, categoryname REGEXP '[^a-zA-Z0-9]', '-')), '.html')
AS
	`link`
FROM
	categories

This partially works, I get the following results:

Code:
C-4-electronics.html
C-5-audio equipment.html
C-6-home entertainment.html
C-7-photography.html
C-8-portable audio.html
C-9-televisions.html
C-10-amplifiers & receivers.html
But there is a problem. My regexp does not seem to be working.

Could anyone please help?

Is there a reason this does not work, because it looks correct and kind of works!

P.S. I am trying to strip out all none-alpha-numeric chars and replace them with a hyphen "-".

Last edited by avera; 04-13-09 at 14:33.
Reply With Quote
  #2 (permalink)  
Old 04-13-09, 11:18
avera avera is offline
Registered User
 
Join Date: Apr 2009
Posts: 3
Just a heads up - I cannot reverse the query because there is no WHERE clause.

(Someone asked me that on anoither forum.)
Reply With Quote
  #3 (permalink)  
Old 04-13-09, 12:04
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
REGEXP can only return "yes" or "no" whether it finds a match

you will have to replace the unwanted characters individually (nested REPLACE functions)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 04-13-09, 14:32
avera avera is offline
Registered User
 
Join Date: Apr 2009
Posts: 3
Yeah - I noticed that it returns 1 or 0.

But I would have imagined that would have given the REPLACE some indication of a match.

Any other ideas?
Reply With Quote
  #5 (permalink)  
Old 04-13-09, 14:58
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by avera
Any other ideas?
yes -- use two columns instead of one, and use your application language (php?) to store the two different strings
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On