PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Logiciels d'hébergement > mailing.database.mysql > Find and replace of portions of text strings
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Find and replace of portions of text strings

Réponse
 
LinkBack Outils de la discussion
Vieux 04/04/2006, 16h34   #1
Karen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Find and replace of portions of text strings

I am very new to MySQL- I currently have an VBA module using a VBSCript
that will find different aspects of a text string that are a unique
text string and turn it into a not so unique text string. Which allows
for a more accurate count of text strings.

example
Item# Text string CountTExt
1 Now is the time to call me at 800-001-0055. 1
2 Now is the time to call me at 800-001-7777. 1

Convert to:
Item# Text string
1 & 2 Now is the time to call me at #########. 2.

Current SQL statement run in Access 2K3 - against a linked MYSQL table.
- Runs very slowly. Would like to move this to MYSQL if possible.

UPDATE combined_logs SET combined_logs.Body2 =
RegExpReplace(RegExpReplace(RegExpReplace(RegExpRe place([body],"http://[^
]*","http://",True,False),"[\d\.\-\(\)]{7,}","##########",True,False),"\d{5}","####",True ,False),"[""\d]{4,6}","####",True,False)
WHERE (((combined_logs.Body2) Is Null) AND
((combined_logs.InOut)="Out"));

VBA Code:

Function RegExpReplace(LookIn As String, PatternStr As String, Optional
ReplaceWith As String = "", _
Optional ReplaceAll As Boolean = True, Optional MatchCase As Boolean =
True)
On Error GoTo RegExpReplace_Error

Dim RegX As Object

Set RegX = CreateObject("VBScript.RegExp")
With RegX
..Pattern = PatternStr
..Global = ReplaceAll
..IgnoreCase = Not MatchCase
End With

RegExpReplace = RegX.Replace(LookIn, ReplaceWith)

Set RegX = Nothing
RegExpReplace_Exit:
Exit Function

RegExpReplace_Error:
MsgBox "Unexpected error - " & Err.Number & vbCrLf & vbCrLf & Error$,
vbExclamation, "Access9db - RegExpRep"
Resume RegExpReplace_Exit

End Function

I understand that the replace function within MYSql replaces the intire
string and the regexp returns the value of True or False.

Is there a way to duplicate the above function within MYSql.

Thanks,

Karen

Navigate: Previous Message · Next Message

  Réponse avec citation
Vieux 04/04/2006, 19h13   #2
Bill Karwin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Find and replace of portions of text strings

Karen wrote:
> I understand that the replace function within MYSql replaces the intire
> string and the regexp returns the value of True or False.


No -- in MySQL, the REPLACE() function takes three arguments: the
string to search, the substring to match, and the replacement string.

mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww');
-> 'WwWwWw.mysql.com'

But that doesn't you, because it doesn't replace regular expression
patterns, it only replaces fixed strings.

I think you are stuck doing your pattern substitution in application
code. Using MS Access & VB might not be the fastest solution. You
might consider Perl or Java.

You might also be able to speed up the operation by executing the UPDATE
against only the rows where the patterns occur:

UPDATE ...
WHERE body REGEXP 'pattern'

At least that won't waste time doing all those regexp replacements on
rows where the pattern doesn't occur.

Another option I can think of is to generate a SQL script of many UPDATE
statements:

SELECT CONCAT(
'UPDATE combined_logs SET body2 = \',
REPLACE(body, '\'', '\'\''),
'\' WHERE primaryKey = ', primaryKey, ';'
) AS update_script
FROM combined_logs
WHERE body REGEXP 'pattern'

Then run the resulting script using the "mysql" command-line tool. This
should run much faster than doing it in VB code.

Regards,
Bill K.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 23h08.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 1,23779 seconds with 10 queries