View Full Version : Removing brackets from a text file
teognost
04-23-2008, 07:31 AM
I have a text file like :
--ApplyTo:[Upgrade]
bla bla
--ApplyTo:[BusinessData]
IF NOT EXISTS(SELECT * FROM syscolumns WHERE id = OBJECT_ID('[og].[ClearVisionExport]') AND name = 'UserComment')
ALTER TABLE [og].[ClearVisionExport]
ADD [UserComment] [VARCHAR] (4000) NULL
--ApplyTo:[None]
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
I need to remove all the brackets after ApplyTo so :
ApplyTo:[Upgrade] becomes ApplyTo:Upgrade
ApplyTo:[BusinessData] becomes ApplyTo:BusinessData
and so on.
I tried to implement a replace step(see the attachment) but I cannot make it working.
Any idea how to do this?
kinook
04-23-2008, 07:40 AM
The expression
ApplyTo:[[(\w+)]]
should be
ApplyTo:\[[(\w+)\]]
(square bracket characters have special meaning in regexes too and must be escaped to be treated as literals by the regex engine).
http://www.visualbuild.com/Manual/regex.htm
teognost
04-23-2008, 07:50 AM
I see,thanks for info!
And what about the other part -from 'Text or regular expressions to replace matches with'?What should be there in order to have the item inside the brackets found previously?
Basically I need to have something like :
ApplyTo:ITEMINSIDEBRACKETS
but I do not know how to put it.
I looked in help but I still do not understand...
kinook
04-23-2008, 07:58 AM
$1 or \1. Your sample worked in my tests after modifying as above and checking the Replace in File step (to include in the build).
4/23/2008 6:56:34 AM: --------------------Starting Build: 'removebrackets.bld'--------------------
4/23/2008 6:56:34 AM: Building project step 'Project steps'...
4/23/2008 6:56:34 AM: Building project step 'Create test file'...
Creating file C:\Temp\test.sql
4/23/2008 6:56:34 AM: Building project step 'Show test file'...
--ApplyTo:[Upgrade]
bla bla
--ApplyTo:[BusinessData]
IF NOT EXISTS(SELECT * FROM syscolumns WHERE id = OBJECT_ID('[og].[ClearVisionExport]') AND name = 'UserComment')
ALTER TABLE [og].[ClearVisionExport]
ADD [UserComment] [VARCHAR] (4000) NULL
--ApplyTo:[None]
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
4/23/2008 6:56:34 AM: Building project step 'Remove ApplyTo brackets'...
3 match(es) found, 3 replacement(s) made in file
4/23/2008 6:56:34 AM: Building project step 'Show test file after changes'...
--ApplyTo:Upgrade
bla bla
--ApplyTo:BusinessData
IF NOT EXISTS(SELECT * FROM syscolumns WHERE id = OBJECT_ID('[og].[ClearVisionExport]') AND name = 'UserComment')
ALTER TABLE [og].[ClearVisionExport]
ADD [UserComment] [VARCHAR] (4000) NULL
--ApplyTo:None
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
teognost
04-23-2008, 08:06 AM
right ,works perfect with $1,thanks a lot!
vBulletin® v3.8.11, Copyright ©2000-2024, vBulletin Solutions Inc.