Is there some way to append something to a search result in JetBrains IDEs or VSCode?
Usually I'd use find and replace and just copy the old result and append things but now I am using regex search over multiple files and I need to add a line to all the results.
Usually using find and replace you'll get something like this:
So instead of replacing the search result I want my input to be added the search result.
This should be useful when using RegEx to edit multiple lines that have things in common.
In my case I was looking to add a field to all my enums that are like:
public enum EnumName {
// field1
// field2...
}
To be like :
public enum EnumName {
// default field
// field1
// field2...
}
Thanks to #LazyOne replies, I've been able to find a way to do what I am looking for by using RegEx Capturing Groups that works in JetBrains IDEs (Intellij help) and VSCode too.
It consists on putting the regular expression we want to add something to in parenthesis in the search field and then in the replace field using $1 $2.. to reference the RegExs given the actual order in the search.
In my case using Jetbrains Rider I was looking to add something to all the enums in my solution, and I simply put my RegEx inside () so it became (.* enum .* .*\{) and then used $1 to reference it like this:
Related
I am working on a large project in Xcode. I'm wanting to search, using the Find Navigator (See Below), for all arrays regardless of their name. I only care about any array that has this format, someArray[index].
Some Examples That Should Match
people[12]
section[0].rows[0]
Should Not Match
people[index]
section[section].row[row]
The regex should only return arrays, it should not return any dictionaries or other types that are not a subscripted array.
Why am I doing this? Well, it appears there have been some issues within our app where devs have not properly handled index out of bounds errors or nil values. There are far too many arrays for me to manually go through line by line to find them, so this is the best option I've come up with and it may not even be possible. If anyone has other recommendations, please feel free to share.
You can create a regex to match any word followed by another word with optional period enclosed by brackets. Something like:
\w+\[\w+(\.\w+)?\]
For more info about the regex above you can check this link
For numbers only use \d+ instead:
\w+\[\d+\]
For more info about the regex above you can check this link
I would like to use a regular expression in the Search panel in Visual Studio Code. In my particular case, I need to find all Pascal Camel-case words in *.ts files.
I use \b([A-Z0-9][a-z0-9]+)* regex and the result is not what I expect:
This is what I get:
This is what I expect:
It looks like I use Search panel in a wrong way or it doesn't work properly.
Any bits of advice, folks?
UPD:
Correct regular expression \b([A-Z][a-z0-9]+)\w+
How i can get all morphology forms of the word?
For example, searching keyword is:
runner
Result should be:
run,running ... etc
You usually don't need one. Use a stemmer, which can do the reverse. ie it removes the "ending", so that matching works, rather than trying to figure out all the possible endings.
https://en.wikipedia.org/wiki/Stemming
ie use morphology, rather than worforms.
http://sphinxsearch.com/docs/current.html#conf-morphology
According to http://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL
queries can use regular expressions on both the values and the keys. While I have no trouble using regex on the values, I'm having a problem with the keys.
The example on the wiki referenced above says (among other examples):
/* finds addr:* tags with value exactly "Foo" */
node[~"^addr:.*$"~"^Foo$"];
So, that's an example of using regex on the keys and the values.
What I am interested in is the name key. Specifically the name:en key. There are a couple problems with searching by name. Not all names are in English, and for those nodes/way/relations whose names are not in English, there is no guarantee there will be a name:en tag with an English version of the name.
In general, there is no way to know in advance if the name will be in English or that there is a name:en tag. If you only ask for name or name:en, you run the risk of finding no hit. (Of course, searching for both is no guarantee of success, either.)
I have a case where I know name fails, but name:en succeeds. That is my test case. I can query the overpass-api.de/api/interpreter using this:
[out:json][timeout:25][bbox:33.465530,36.156006,33.608615,36.574516];
(
node[name~"duma",i][place];
way[name~"duma",i][place];
>;
relation[name~"duma",i][place];
node["name:en"~"duma",i][place];
way["name:en"~"duma",i][place];
>;relation["name:en"~"duma",i][place];
);
out center;
see it on overpass
and it works fine ("duma" is not found through name, but it is found with name:en), but I find it lengthy and somewhat repetitive.
I would like to use a regular expression involving the name and name:en tags, but either the server does not understand the query or I simply am using an incorrect regex.
Using the example shown in the wiki: node[~"^addr:.*$"~"^Foo$"]
I have tried:
[~"name|name:en"~"duma",i]
[~"name.*"~"duma",i]
[~"^name.*$"~"duma",i]
and several others. I even mimicked the example with [~"^name:.*"~"duma",i] just to see if anything would be returned.
Does overpass-api.de recognize regular expressions on the keys or do I just have the regex wrong? I don't get an error from overpass-api.de, just the coordinates of the bbox and an empty result. It's usually very strict about reacting to a poortly formatted query. Thanks in advance.
That's really a bug in the Overpass API implementation concerning case-insensitive key regex matching, see this Github ticket for details.
For the time being, you can already test the patch on the development box:
http://overpass-turbo.eu/s/b1l
BTW: If you don't need case-insensitive regexp matching, this should already work on overpass-api.de as of today.
I'm optimizing my code at the moment (android game), and wanted to replace all foreach(for(:)) with normal fors. Is there a way to find them all? Ctrl-F only looks through the current file and Ctrl-H doesn't seem to find any java constructs (not sure if right word: ifs, whiles, accessors etc.). Preferably without a plugin, but any answer accepted. It would also be nice if there would be a possibility to search for any string (* in Search).
TL;DR: Looking for way to find all foreaches in eclipse.
First of all, I must say, this sounds like a really strange optimization. Keep in mind that if you have, say, a LinkedList you would be far worse of going through a
for (int i = 0; i < list.size(); i++) {
element = list.get(i);
...
loop, than using an iterator (which for-each loops does). Smells micro-optimizations long way to me.
That said, here's a solution for you:
Make sure the root source folder is selected
Click Search / File Search
Mark Scope as "Selected resources"
Mark Regular expression
Search for a regular expression such as for\s*\(.*:
The expression matches strings on the form for, followed by some white whitespace, followed by ( followed by some characters, followed by : (which kind of characterizes a Java for-each loop).
Right-Click on the project, choose search and you're able to replace all for-commands with a regular expression like for(.*;.*;.*) with other expressions you want to.