Community
    • Login

    Need help with a regex search and replace

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 2 Posters 3.1k Views
    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 HobleyS
      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 FrankC 1 Reply Last reply Reply Quote 0
      • Claudia FrankC
        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 HobleyS
          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 FrankC 1 Reply Last reply Reply Quote 0
          • Claudia FrankC
            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 HobleyS
              Steve Hobley
              last edited by

              Thanks! That did the trick.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors