Match string inside function [closed] - regex

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want to search for imports in my node modules from visual studio codes regex search, the problem is that i only want to search for imports that are inside functions and not in the whole file. How would i go about doing this?
const a = require('a'); // shouldn't match
function func() {
const b = require('b'); // should match
}

Despite the growing popularity of such features (search in functions, search outside of comments, search in strings, etc), VSCode still doesn't have built-in support for such these.
You'll have to use find with regular expressions for this one, but good luck on building the regex for "a particular pattern inside a function". A good hack that doesn't work all of the time is to detect indentation before your pattern: ^\s+.*YOURPATTERN

Related

Using RegEx to match at least two words

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 hours ago.
Improve this question
I have an app that lets me search files thousands of folders on my pc to identify any number of criteria. I need a RegEx to search for folders that have files named both poster.jpg AND poster.png only. There could be other similarly named files that I don’t care about. I only want to match poster.jpg and poster.png. Nothing I have tried thus far has worked.
According to the application help it uses ECMA-262 grammar but I looked at the documentation and I’m more confused than when I started. Help please.

From String to Function [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'd like to know if there is a way to transform a string into a function em c++. For example if I have the string: "x+y" it'd create the function and by replacing x and y, get the value of it.
In Java there is this API https://www.objecthunter.net/exp4j/index.html, so I was wondering if there is something similar.
There are many possible methods one could use to transform a string into a "function". Many of those involve parsing the string and building a function-like object out of it.
A lightweight and portable solution would be to use ExprTk, a mathematical expression library developed by Arash Partow.
The main page contains various usage examples.

How to wrap all strings in a project with a macro / function? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Ok so I have a string encryption thing that goesXorStr( "" ).
How can I put this on all strings without doing them one by one?
You can use the fact, that "Find and Replace" functionality also provides support for regular expressions. Thus, you may easily find all strings, capture them and wrap with XorStr().
In "Find" field, ((\".+?\")|('.+?')) will match all strings with double or single quotes. If you want only the double-quoted, reduce this to (\".+?\").
In "Replace with" field, use: XorStr($1).

how to find if a vector contains anything matching to regular expression [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have questions related to project I am working on. I have thought about these, and have some suspicions, but I would love to hear the community's input as well.
I have a std::vector<std::string> x which contains some regular expressions like "^OPEN$" and "^CLOSE$". I also have a std::vector<std::string> y which contains some strings like "OPEN", "OPEN23", "CLOSE", "CLOSE4", "XS_234$".
Now i have to check if vector y has at least one matching the regular expression from vector x.
Limitations:
No external supporting libraries (for example I can't use boost)
No C++11 or newer.
QRegEpx will do the job. Create a QRegExp for each of your tokens, then run them against x to identify which one it is.
Then run QString(y).contains(matchedRegExp) to get your answer.
EDIT: you can also do:
QStringList list = QString(y).split(", ", QString::SkipEmptyParts).filter(matchedRegExp);
bool answer = list.size() > 0;
That way you have the list if you need it.

Find .Include() chains using Visual Studio Regex Search [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have recently been asked to take over a large LOB application that uses Entity Framework. Many of the db calls being made use several (>5) Includes, which causes some very heavy query inefficiency. I want to use Visual Studio's search functionality to find some of these include chains. As a quick example, one might look like:
var res = ObjectContext.Items.Include("Details")
.Include("Users").Include("Users.Info");
I'd like to find any instance of more than 1 include, and match regardless of what the include path is.
How can I structure a search to identify these chains? Any help is most appreciated!
VS2012 uses .NET's regex flavor so you could do something like
(?:[.]Include[(]\s*"[^"]*"\s*[)]\s*){2,}
This matches one .Include("something") plus any white space after it and then requires at least two repetitions of this pattern. Note that you'll get problems if your strings contain quotes or you have verbatim strings in there. In that case the "[^"]*" would have to be a bit more elaborate.