473,569 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.B ody2 =
RegExpReplace(R egExpReplace(Re gExpReplace(Reg ExpReplace([body],"http://[^
]*","http://",True,Fals e),"[\d\.\-\(\)]{7,}","######## ##",True,False) ,"\d{5}","####" ,True,False),"[""\d]{4,6}","####",T rue,False)
WHERE (((combined_log s.Body2) Is Null) AND
((combined_logs .InOut)="Out")) ;

VBA Code:

Function RegExpReplace(L ookIn As String, PatternStr As String, Optional
ReplaceWith As String = "", _
Optional ReplaceAll As Boolean = True, Optional MatchCase As Boolean =
True)
On Error GoTo RegExpReplace_E rror

Dim RegX As Object

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

RegExpReplace = RegX.Replace(Lo okIn, ReplaceWith)

Set RegX = Nothing
RegExpReplace_E xit:
Exit Function

RegExpReplace_E rror:
MsgBox "Unexpected error - " & Err.Number & vbCrLf & vbCrLf & Error$,
vbExclamation, "Access9db - RegExpRep"
Resume RegExpReplace_E xit

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

Apr 4 '06 #1
1 2793
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.my sql.com', 'w', 'Ww');
-> 'WwWwWw.mysql.c om'

But that doesn't help 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.
Apr 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3713
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
1
1467
by: Jeffrey | last post by:
I would appreciate suggestions for a general strategy I could use to update a bunch of HTML files. Specifically I need to replace sevaral instances of one string with another string in each of a few dozen HTML files. While I already plan to use RegEx to do the actual replacement, what should I be doing to open, update, and save each of...
4
3836
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said, that the split method and the regex.replace method was better than the string.replace method and replace function. I did not believe that.
4
22982
by: Lauren Wilson | last post by:
Hi folks, We have a need to replace sub strings in certain message text. We use the Office Assistant to display help and often use the imbedded formatting commands. Those of you who have used them know they look like this: "{cf 5}" or "{cf 0}" or "{ul 1}" or "{ul 0}", etc. The commonality they have is that they are always 6 charters long...
5
3389
by: peter | last post by:
Hello all, I'm looking for an advice. Example (one block in ascii file): $------------------------ NAME='ALFA' CODE='x' $------------------------
3
1488
by: teo | last post by:
I have a text. Inside the text the "hallo" word occurs five time. I need to replace "hallo" with "hallo world". Unfortunately I get this: hallo world world world world world
3
16910
by: TOXiC | last post by:
Hi everyone, First I say that I serched and tryed everything but I cannot figure out how I can do it. I want to open a a file (not necessary a txt) and find and replace a string. I can do it with: import fileinput, string, sys fileQuery = "Text.txt" sourceText = '''SOURCE'''
2
3306
by: rengask | last post by:
I got the code to find and replace within an open text file. ------------------ Private Sub cmdFile_Click() Dim strTemp As String txtFile = "" dlg.FileName = "*.*" dlg.ShowOpen If Dir(dlg.FileName) <> "" Then
5
8339
by: neeludhiman | last post by:
Hi All, Can someone please help me with the code in C / C++ to find a string in an input text file and replace it with another string in output text file. The catch is that white spaces in the input file should be retained in output file. And, if possible we should be able to replace multiple search strings with multiple replace strings. e.g;...
0
7698
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.