?
Solved

Regex

Posted on 2013-05-30
9
Medium Priority
?
401 Views
Last Modified: 2013-05-31
In a .sql script file I would like to remove ALTER TABLE [dbo].[ANYTABLE] DISABLE CHANGE_TRACKING

How to achieve using regex replace? Please assist.
0
Comment
Question by:Easwaran Paramasivam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 49

Expert Comment

by:PortletPaul
ID: 39207129
why regex replace? is it one script?
(i.e.why not just edit the script many editors will do this easily)
0
 
LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 39207141
It has Thousands of occurrences. Doing one by one is talking long time. Thats why.
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 39207148
use a text editor, or post the file here perhaps
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 35

Expert Comment

by:Terry Woods
ID: 39209240
Did you know there is a Regular Expressions topic area? Several experts provide excellent help there.

Anyway, different regex tools have different syntax, so it would help if you name the tool you're using eg Notepad++

I'll assume the values indicated with square brackets represent variable text.

A simple regex pattern that would work in most tools is this:
ALTER TABLE \w+\.\w+ DISABLE CHANGE_TRACKING

(replace it with an empty string)

Tested here:
http://www.myregextester.com/?r=7bba67a5
0
 
LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 39210040
Please do refer attached image. It is not working in SSMS.
RegexTest.jpg
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39210046
Does the text actually have the square brackets or not? (or are they there sometimes?)
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 1000 total points
ID: 39210054
After looking at this guide, I suggest you try pattern:
ALTER:b+TABLE:b+[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+:b+DISABLE:b+CHANGE_TRACKING

If square brackets are always or sometimes present, then try this:
ALTER:b+TABLE:b+\[*[a-zA-Z0-9_]+\]*\.\[*[a-zA-Z0-9_]+\]*:b+DISABLE:b+CHANGE_TRACKING

(Updated to allow multiple spaces between words)
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39210062
Let me know how you go.
0
 
LVL 16

Author Closing Comment

by:Easwaran Paramasivam
ID: 39212313
This is what I look for!! Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question