none
Regex for Find and Replace across multiple lines RRS feed

  • Question

  • I have a tsql file open and doing a Find and Replace in VS 2017. I am a regex newbie.  I have several similarly named fields that need to have their size changed.

    For example, want to fine the 12 column names that match the following pattern GZBDGMVP[0-9][0-9]

    GZBDGMVP01 decimal(5,1)
    thru
    GZBDGMVP12 decimal(5,1)

    and change to 

    GZBDGMVP01 decimal(6,1)
    thru
    GZBDGMVP12 decimal(6,1)

    sometimes it is broken across two lines

    GZBDGMVP09
    decimal(5,1)

    also confused about the REPLACE part. How to keep everything original (like the column name) but only change the 5 to a 6


    Friday, May 4, 2018 3:28 PM

All replies

  • Try the next expression:

       \b(?<x>GZBDGMVP(0[1-9]|1[0-2])(\s|\r|\n)+decimal\()5(?<y>,\d+\))

    The replacement is:

       ${x}6${y}


    • Edited by Viorel_MVP Friday, May 4, 2018 4:24 PM
    Friday, May 4, 2018 4:20 PM
  • First, I added tab |\t to the string of special character. But no matches were returned.  

    \b(?<x>GZBDGMVP(0[1-9]|1[0-2])(\s|\r|\n|\t)+decimal\()5(?<y>,\d+\))

    Then shorted the Find to below and it returned my matches, but guessing that I need the other stuff for the REPLACE

    \bGZBDGMVP(0[1-9]|1[0-2])(\s|\r|\n|\t)+decimal


    • Edited by TheBrenda Friday, May 4, 2018 6:40 PM
    Friday, May 4, 2018 6:25 PM
  • Viorel_ - can you help me out. want to understand.  Your suggested Find does not work for this example. 

    \b(?<x>GZBDGMVP(0[1-9]|1[0-2])(\s|\r|\n)+decimal\()5(?<y>,\d+\))

    GZBDGYVP01 (decimal 5, 1) NOT NULL,

    Monday, May 7, 2018 2:19 PM