简体   繁体   中英

javascript regex to prepend string to variable names jupyter

I am migrating a Python code from a Jupyter notebook to a module.
The code presents many variables named like name_arr (eg. time_arr ).
I would like to modify all of them prepending TC. , where TC is the instance
of a class I am progressively building on the side in the python module.

I have a rough idea of how to achieve this on vim (using sed , loops and ifs)
but I'd like to learn how to do it from within Jupyter using Javascript regex.

I've seen many answers on how to do it in a Javascript environment (I don't know Java).
What I don't get is how to do it in Jupyter Find & Replace tool.

Following a JS regex tutorial, I have tried _arr$ 在此处输入图像描述 but this clearly does not capture all occurrences of the suffix.

Can somebody provide some insight/suggestion on how to do this?
Doing it by hand feels like a silly task, prone to mistakes.
Thank you

You use

\w+_arr\b

and replace with

TC.$&

Details:

  • \w+ - one or more word chars
  • _arr - a substring
  • \b - a word boundary.

$& stands for the whole match value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM