Need help with a regex search and replace

  • 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”


    WriteSession(“KeyOfSomeKind”, “ValueOfSomeKind”)


    var x = Session(“KeyOfSomeKind”)


    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?


  • 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 ;-)


  • 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?

  • 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.


  • Thanks! That did the trick.

Log in to reply