Solved

Regex

Posted on 2013-05-30
9
378 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

932 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

11 Experts available now in Live!

Get 1:1 Help Now