简体   繁体   中英

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. I am trying to learn how to better search for strings, variables, etc. in Source Graph so I can solve coding issues at work. I am not a coder/programmer/engineer but I have some general knowledge of programming in C and Python and using Query Languages.

I have gone to Source Graph's instructional page about RegEx but I honestly have a hard time understanding it.

Example: I am trying to find " Delete %(folder_name)s and %(num_folders)s other folder from your ... " without the actual quotes and ellipses.

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.

If I copy and paste that above line into Source Graph, I get no returns.

Here is what I found how the source file actually looks like in Source Graph:

"Delete \“%(folder_name)s\” and %(num_folders)s other folder from your ..." , again without actual quotes and ellipses.

I would have no idea that the \“ and \\201d were there in the original code. 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

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

Sorry if this doesn't make any sense. This is my very first Stack Overflow post.

I can't the snippet you mentioned on sourcegraph.com, so I assume you are hosting Sourcegraph yourself.

In general, you could search for a term like Delete \“%(folder_name)s without turning on regular expressions to get literal matches. 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:

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

https://regex101.com/ is my personal recommendation for learning more about how regular expressions work.

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