Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Need help with a regex search and replace

    Help wanted · · · – – – · · ·
    2
    5
    2822
    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.
    • Steve Hobley
      Steve Hobley last edited by

      I’ve inherited an old ASP Classic website with over 2000 files in it :(

      I need to rework the session code, replacing

      Session(“KeyOfSomeKind”) = “ValueOfSomeKind”

      with

      WriteSession(“KeyOfSomeKind”, “ValueOfSomeKind”)

      and

      var x = Session(“KeyOfSomeKind”)

      with

      var x = ReadSession(“KeyOfSomeKind”)

      [OK, so the last one is just a regular S+R, but I wanted to include it for full complexity]

      Is there a regex notation for Notepad++ that could do this over all the files?

      Steve

      Claudia Frank 1 Reply Last reply Reply Quote 0
      • Claudia Frank
        Claudia Frank @Steve Hobley last edited by

        Hello @Steve-Hobley

        you can do regex with Find in Files dialog.

        Add you regexes for find and replace,
        maybe modify the filter so that only asp code pages get accessed
        set directory to your wwwroot directory and check in-all subfolders
        check regular expression in search mode section
        press find in files to see if the code is as expected and to have a reference of the files which will get modified
        then press replace in all files

        Be sure you have a backup in case of a disaster ;-)

        Cheers
        Claudia

        1 Reply Last reply Reply Quote 0
        • Steve Hobley
          Steve Hobley last edited by

          Thanks… I got as far as running a regex for find in files, but what I really need help with is constructing the regex expression.
          Has anyone done anything similar?

          Claudia Frank 1 Reply Last reply Reply Quote 0
          • Claudia Frank
            Claudia Frank @Steve Hobley last edited by

            Hello @Steve-Hobley,

            from the given example I would do it like

            find: ^\s*(Session\()(".*?")\)\s*=\s*(".*?")[\t\f ]*$
            replace: Write\1\2, \3\)
            

            It is assumed that before Session word there are either non or multiple whitespace chars only nothing else
            and that the code is like provided, no additional spaces like

            Session ( "KeyOfSomeKind" ) = "ValueOfSomeKind"
            

            As you already said the second is a simple Replace.

            Cheers
            Claudia

            1 Reply Last reply Reply Quote 1
            • Steve Hobley
              Steve Hobley last edited by

              Thanks! That did the trick.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Copyright © 2014 NodeBB Forums | Contributors