Solved

Regex

Posted on 2013-05-30
9
394 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
Technology Partners: 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!

 
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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

690 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