简体   繁体   English

javascript 正则表达式将字符串添加到变量名 jupyter

[英]javascript regex to prepend string to variable names jupyter

I am migrating a Python code from a Jupyter notebook to a module.我正在将 Python 代码从 Jupyter 笔记本迁移到模块。
The code presents many variables named like name_arr (eg. time_arr ).该代码显示了许多名为name_arr的变量(例如time_arr )。
I would like to modify all of them prepending TC.我想在TC. , where TC is the instance ,其中 TC 是实例
of a class I am progressively building on the side in the python module.的 class 我正在 python 模块的侧面逐步构建。

I have a rough idea of how to achieve this on vim (using sed , loops and ifs)我大致了解如何在vim上实现这一点(使用sed ,循环和 ifs)
but I'd like to learn how to do it from within Jupyter using Javascript regex.但我想学习如何在 Jupyter 中使用 Javascript 正则表达式来做到这一点。

I've seen many answers on how to do it in a Javascript environment (I don't know Java).我已经看到很多关于如何在 Javascript 环境中执行此操作的答案(我不懂 Java)。
What I don't get is how to do it in Jupyter Find & Replace tool.我不明白如何在 Jupyter 查找和替换工具中执行此操作。

Following a JS regex tutorial, I have tried _arr$遵循 JS 正则表达式教程,我尝试_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.$& TC.$&

Details:细节:

  • \w+ - one or more word chars \w+ - 一个或多个单词字符
  • _arr - a substring _arr - substring
  • \b - a word boundary. \b - 单词边界。

$& stands for the whole match value. $&代表整个匹配值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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