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

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.

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.

Which is better to use: regex.containsMatchIn(String) or String.contains(regex) and why? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
If i have a String called "text" and a Regex (called "regex" for ease) i want to check it against, should i use:
regex.containsMatchIn(text)
or should i use:
text.contains(regex)
Both seem to be successful but i am unsure of the best practices concerning this.
Use whichever one makes your code easier to read. There is no difference between them because text.contains(regex) calls the regex.containsMatchIn(text) As per Strings.kt source code:
#kotlin.internal.InlineOnly
public inline operator fun CharSequence.contains(regex: Regex): Boolean = regex.containsMatchIn(this)
The Kotlin documentation says:
contains
Returns true if this char sequence contains the specified other sequence of characters as a substring.
containsMatchIn
Indicates whether the regular expression can find at least one match in the specified input.
It looks like both do pretty much the same thing, so functionally it doesn't matter too much which you use.
However, since you're dealing with regex, I feel like using containsMatchIn is more appropriate since it's part of the regex library and intended for that purpose specifically.
Where contains can be used for more than just regex, e.g. for finding if 'flow' is a substring of 'overflow'. So, it's likely less appropriate to use it for regex, if we're being picky.

Match string inside 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 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

Inverted index for regex? Regex search engine? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I was wondering if it would be possible at all to build an inverted index for all possible regular expressions... I have had a few ideas, but they are extremely vague at the moment.
My reasoning behind this is because I think that a search engine that uses regex would be pretty useful (I'm sure many people would agree), although the problem with a search engine is that there is quite a lot of things to search. This is why there are inverted indexes, I guess.
Maybe something similar? I don't really know.
Here's a description of my idea:
The search engine should be a regex search engine. Instead of being like a normal search engine which only matches words, this will match specific regex specified by the user.
an example of a search: [^ ]*ell[^ ]* .*\.
something like that, for example. the reasoning behind this is that sometimes i want to search something that can't be found due to the limitedness of normal search engines.
it'll be a simple sed-like regex, maybe a bit javascripty.
they are all similar anyway (with the basics)
Edit: I've seen regular expression search engine, but it's not what I am asking. I'm wondering if it's possible to build one.
Edit 2: Maybe an inverted index that has bits of words, and numbers (and their length), etc. Maybe some kind of table where I can quickly pick things out, so if I have a number of a certain length in my regex, I can quickly filter all the numbers that i have indexed that have that length?
If I combine those ideas, I just realized that maybe multiple searches, but with a shrinking data source, until everything that is left is what matches the regex? Eg: ell.\*\\. would search for everything with e, then everything with a l following the a, then everything with another l following the el, and then any number of characters followed by a ..

Converting Regular Expressions For Use With VBA [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 9 years ago.
Improve this question
Forgive me if this seems basic, but I'm new to regular expressions, and I can't seem to find general information that isn't example driven.
Basically, I'd like to know what to keep in mind when converting regular expressions found around the internet for use with vba. Is it as simple as "oh, just change the non-greedy operator to this ...", or is it involved on a level that I really need to find VBA specific expressions, or get better at writing my own.
My specific example involves converting this phone number pattern
^((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}$
But i'm really more interested in either a general approach, or an affirmation of its futility. Thanks!
Following up on Cor_Blimey and funkwurm's comments, I have used VBScript 5.5 regexes in Office 2003 and Office 2007 VBA with good success. Details here. For anything more complicated than () and [] groups, I have found writing from scratch more effective than trying to modify an existing expression.