简体   繁体   English

如何在 Source Graph 中正确使用 RegEx?

[英]How can I use RegEx in Source Graph properly?

I have virtually no knowledge of how to use Source Graph but I do know what Source Graph is and what RegEx is and its application across platforms.我几乎不知道如何使用 Source Graph,但我知道 Source Graph 是什么,RegEx 是什么以及它的跨平台应用程序。 I am trying to learn how to better search for strings, variables, etc. in Source Graph so I can solve coding issues at work.我正在尝试学习如何在 Source Graph 中更好地搜索字符串、变量等,以便我可以解决工作中的编码问题。 I am not a coder/programmer/engineer but I have some general knowledge of programming in C and Python and using Query Languages.我不是编码员/程序员/工程师,但我对 C 和 Python 编程以及使用查询语言有一些一般知识。

I have gone to Source Graph's instructional page about RegEx but I honestly have a hard time understanding it.我已经访问了Source Graph关于 RegEx的说明页面,但老实说我很难理解它。

Example: I am trying to find " Delete %(folder_name)s and %(num_folders)s other folder from your ... " without the actual quotes and ellipses.示例:我正在尝试查找“从您的...中删除 %(folder_name)s 和 %(num_folders)s 其他文件夹”而没有实际的引号和省略号。

That is how I receive the code at work but this apparently is not how it is represented in Source Graph in its source file.这就是我在工作中接收代码的方式,但这显然不是它在源文件中的 Source Graph 中的表示方式。

If I copy and paste that above line into Source Graph, I get no returns.如果我将该行复制并粘贴到 Source Graph 中,则不会得到任何回报。

Here is what I found how the source file actually looks like in Source Graph:这是我在 Source Graph 中发现的源文件的实际外观:

"Delete \“%(folder_name)s\” and %(num_folders)s other folder from your ..." , again without actual quotes and ellipses. "Delete \“%(folder_name)s\” and %(num_folders)s other folder from your ..." ,同样没有实际的引号和省略号。

I would have no idea that the \“ and \\201d were there in the original code.我不知道 \“ 和 \\201d 在原始代码中。 Is there a way around this?有没有解决的办法?

What I usually have to work with and figure out how to find in Source Graph are singular variables or strings: %(num_folders)s我通常必须使用并弄清楚如何在源图中找到的是奇异变量或字符串:%(num_folders)s

This is a problem because the fewer items I have for searching, the harder it is to hunt down their source.这是一个问题,因为我要搜索的项目越少,就越难找到它们的来源。 I don't know who the author/engineer is until I find the code in Source Graph and check the blame feature (sadly it's a little disorganized at my work).我不知道作者/工程师是谁,直到我在 Source Graph 中找到代码并检查了blame 功能(遗憾的是它在我的工作中有点混乱)。

Sorry if this doesn't make any sense.对不起,如果这没有任何意义。 This is my very first Stack Overflow post.这是我的第一篇 Stack Overflow 帖子。

I can't the snippet you mentioned on sourcegraph.com, so I assume you are hosting Sourcegraph yourself.我看不到你在 sourcegraph.com 上提到的片段,所以我假设你是自己托管 Sourcegraph。

In general, you could search for a term like Delete \“%(folder_name)s without turning on regular expressions to get literal matches.通常,您可以搜索像Delete \“%(folder_name)s这样的术语,而无需打开正则表达式来获取文字匹配。 If you want to convert this into a regular expression, you would need to escape it like this:如果要将其转换为正则表达式,则需要像这样转义它:

Delete \\u201c%\(folder_name\)s

If %(folder_name) is meant to be a placeholder for any other expression, try this one instead:如果%(folder_name)打算作为任何其他表达式的占位符,请尝试使用以下方法:

Delete .*s and .*s other folder from your

https://regex101.com/ is my personal recommendation for learning more about how regular expressions work. https://regex101.com/是我个人的建议,用于了解有关正则表达式如何工作的更多信息。

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

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