Solved

Regex

Posted on 2013-05-30
9
374 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
  • 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now