Community
    • Login

    Regular Expression with find a pattern and replace

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 3.4k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • shashi bhosaleS Offline
      shashi bhosale
      last edited by

      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
      )
      AS

      Its not case sensitive.

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP Offline
        PeterJones @shashi bhosale
        last edited by PeterJones

        @shashi-bhosale ,

        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
        )
        AS
        
        

        and 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
        \s character escape sequences
        * multiplying operators
        \r\n control characters (note that they are case sensitive)

        -—

        Useful References

        • Please Read Before Posting
        • Template for Search/Replace Questions
        • FAQ: Where to find regular expressions (regex) documentation
        • Notepad++ Online User Manual: Searching/Regex
        1 Reply Last reply Reply Quote 1

        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
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors