Solved

Regex

Posted on 2013-05-30
9
386 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 48

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 48

Expert Comment

by:PortletPaul
ID: 39207148
use a text editor, or post the file here perhaps
0
Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

 
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 250 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with SQL joins 9 56
SQL Server Degrading on Write 13 72
Query group by data in SQL Server - cursor? 3 65
Loops and updating in SQL Query 9 66
Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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