Menu

serach reg exp

claudio C.
2021-05-15
2021-05-17
  • claudio C.

    claudio C. - 2021-05-15

    hi all, I need to manipulate files looking for and modifying some tags, transforming capital letters where present into lowercase. For the search I used regular expressions. This regular expression works perfectly in the npp ++ search and replace command but does not work in a python script. The command in question is: editor.rereplace ("((\ /) *) ([a-zA-Z] +) ((\ d) +) "," $ 1 (\ L $ 3) $ 4 "). Suggestions? thanks

     
    • Sasumner

      Sasumner - 2021-05-15

      Probably you need to use "raw strings" so that your backslashes aren't consumed by Python's interpretation and not given to the regex engine.

      So, instead of:

      editor.rereplace("abc", "def")
      

      do:

      editor.rereplace(r"abc", r"def")

       
  • claudio C.

    claudio C. - 2021-05-15

    hello, but the command editor.rereplace () unlike editor.replace () is not already addressed for the regex engine? if not what is the difference? thanks

     
  • claudio C.

    claudio C. - 2021-05-15

    Taking the addition of "r" for granted so that my backslashes are processed by the regex engine, the problem of uppercase to lowercase characters with "\ L" remains. I doubt the correct syntax to bring everything in lowercase associated with group # 3:

    (\L$3)
    

    Is this correct?
    Thanks

     
    • Sasumner

      Sasumner - 2021-05-17

      It appears there may be a problem with the special casing stuff in Pythonscript...see https://github.com/bruderstein/PythonScript/issues/199

       
      • claudio C.

        claudio C. - 2021-05-17

        hello, yes that's my post :-)

         

        Last edit: claudio C. 2021-05-21

Log in to post a comment.