Regular Expression with find a pattern and replace
-
Looking to find a block where starts with CREATE procedure and ends with ) as
and In replace add additional line select @site = ‘Site’ at the end.CREATE PROCEDURE [dbo].[ki_APSGetTopLevelDemand_BKUP]
(
@IpRefType AS VARCHAR(100),
@IpRefNum AS VARCHAR(100),
@IpRefLine AS INT
)
ASIts not case sensitive.
-
When I read your post earlier this week, I had hoped someone else would chime in, because I was pretty busy. Sorry no one else had a chance to reply before I finally found a spare moment to go back through unanswered questions.
If I have interpreted your request, then if I start with
CREATE PROCEDURE [dbo].[ki_APSGetTopLevelDemand_BKUP] ( @IpRefType AS VARCHAR(100), @IpRefNum AS VARCHAR(100), @IpRefLine AS INT ) AS blah blah blah CREATE PROCEDURE [dbo].[ki_APSGetTopLevelDemand_BKUP] ( @IpRefType AS VARCHAR(100), @IpRefNum AS VARCHAR(100), @IpRefLine AS INT ) ASand use
- FIND =
(\)\s*AS) - REPLACE =
$0\r\n@site = 'Site' - SEARCH MODE = regular expression
After doing the two replacements (or a REPLACE ALL), I get what I think you want:
CREATE PROCEDURE [dbo].[ki_APSGetTopLevelDemand_BKUP] ( @IpRefType AS VARCHAR(100), @IpRefNum AS VARCHAR(100), @IpRefLine AS INT ) AS @site = 'Site' blah blah blah CREATE PROCEDURE [dbo].[ki_APSGetTopLevelDemand_BKUP] ( @IpRefType AS VARCHAR(100), @IpRefNum AS VARCHAR(100), @IpRefLine AS INT ) AS @site = 'Site'If you want to know more about the individual tokens in my search and replace, look at the official search/regex section of the usermanual, linked below, for the following concepts
token see usermanual section about parentheses capture groups \scharacter escape sequences *multiplying operators \r\ncontrol characters (note that they are case sensitive) -—
Useful References
- FIND =
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login