Eclipse file search - How do I search for a particular string - regex

In Eclipse, using the File Search feature, I am trying to do a file search over a large package for files containing <button and class="someclass", but without type="button".
In a more general sense, how do I search for some text while excluding results of they contain another bit of text?

CTRL + H and then choose File Search, there you can check the Regular expression option.
In order to get what you want, you can try entering something like this:
^(?!.*type="button").class="someclass".$
You can get more general regex information for Eclipse's File Search at this page.

Related

Inteliij - searching in the whole project - replace all characters

Using IntelliJ IDEA I am facing a problem while searching in the whole project for a file with some text.
I click ctrl + Shift + F and I would like to find rows where are divs with class="X" but I don't know the correct order.
I would like to write something like that: div*class="X" but it doesn't work.
Press Ctrl+Shift+F and type in the search bar (div).*(class="X").
In case the class X can be located anywhere in the string, for instance:
<div class="another-class X"></div>
change your regex like this: (div).*(class=".*X")
Also, make sure you have selected the property Regex (see below image).
For instance here I searched for all html files where there is a div with class="row".
I've used this on IntelliJ IDEA 2018.1.5 (Ultimate Edition) Build #IU-181.5281.24 and it works like charm.

Search for multiple strings in several files with Sublime 3 using AND

This previous (similar) question of mine Search for multiple strings in several files with Sublime 3 was answered with a way to search for multiple strings in multiple files in SublimeText, using the regex OR operator:
Find: (string1|string2)
Where: <open folders>
This works perfectly for searching files where either string1 OR string2 is present. What I need now is to search in lots of files for both strings present. I.e., I need to use the AND operator.
I looked around this question Regular Expressions: Is there an AND operator? and also this one Regex AND operator and came up with the following recipes:
(?=string1)(?=string2)
(?=.*string1)(?=.*string2)
(string1 string2)
(string1\&string2)
but none of them work.
So the question is: how can I search multiple strings in several files at once with SublimeText?
(I'm using SublimeText 3103)
Add: the strings are not necessarily in the same line. They can be located anywhere within each file. For example, this file:
string1 dfgdfg d dfgdf
sadasd
asdasd
dfgdfg string2 dfgdfg
should trigger a match.
Open sublime Text and press
Shift+Ctrl+F
or click on the Find in Files options under Files tab. The above is keyboard shortcut for this option. When you press above key, these are following options
When you select ... button from above, you get 6 options which are Add Folder or Add Open Files or Add Open Folders
To search strings that occur in the same line
Use the following regex for your and operation
(?=.*string1)(?=.*string2)
I am using the following regex
(?=.*def)(?=.*s)\w+ <-- \w+ will help in understanding which line is matched(will see later)
and I am searching within current open files
Make sure the Use Buffer option is enabled (one just before Find). It will display the matches in a new file. Also make sure the Show Context (one just before Use Buffer) option is enabled. This will display the exact line that matches. Now Click on Find on the right side.
Here is the output I am getting
See the difference in background color of line 1315 and 1316(appearing in left side). 1316 is matched line in designation file
This is the image of last part
There were total 6 files that were opened while I used this regex
For finding strings anywhere in file
Use
(?=[\s\S]*string1)(?=[\s\S]*string2)[\s\S]+
but it will kill sublime if number of lines increases.
If there are only two words that you need to find, the following will work super fast in comparison to above
(\bstring1\b[\S\s]*\bstring2\b)|(\bstring2\b[\S\s]*\bstring1\b)

Add a line after another line in multiple files

I have opened 100 files like this:
[database]
server=SQL01
db=milli
authentication=auServer
[Misc]
Now I need to add the same line like this
[database]
server=SQL01
db=milli
authentication=auServer
username=user1
[Misc]
How can I do this, probably some sort of regex?
You could simply do this with Notepad++ using the Find in Files feature.
Put authentication=auServer in the Find what text box, authentication=auServer\r\nusername=user1 in the Replace with text box, *.* in the Filters drop down, C:\some directory in the Directory drop down, tick the In all sub-folders check box, and switch the Search Mode to Extended.
Then just click Replace in Files and you're done.
You could try using the Find in files tab on the search dialogue. Make sure Regular expression selected. Set the search string to (db=milli\r\nauthentication=auServer\r\n)(\r\n\[Misc\]) and the replacement to \1username=user1\r\n\2. Then click Replace in files.
Note that the above will add the line in ALL matching places in the files. To specify the files use the Filter and Directory fields, also make sure that the three tick boxes beneath the Close button are correct.
The Replace in files should be avoided unless you are confident that it will not destroy your files.

eclipse file name pattern search with regular expression

I have a lot of java files:
Foo01.java
Foo02.java
Foo03.java
Foo04.java
Foo05.java
Foo01Bar.java
Foo01Bar.java
Foo02Bar.java
Foo03Bar.java
Foo04Bar.java
Foo05Bar.java
And I need to replace an expression in and only in FooXX.java classes.
Using CTRL + H in eclipse, in the file name pattern, I tried Foo(\d\d).java, but It does not work. If I write Foo*.java, every FooXXBar.java will also appears, and I don't want to.
What's the way to do it?
I don't think eclipse has the capability to do full regular expressions on file names. As far as I know you can use * to match any string and ? to match any single character for a file. As a result if your file list is similar to the above you can search for:
Foo??.java
For more complex file searches you probably need to use a combination of the unix/windows command line tools (depending on your OS choice).

Search multiple strings in eclipse

I need to search throughout the work-space for all files containing "String1" or "String2".How to achieve this in eclipse search ?
Search -> File... In Containing text enter String1|String2 and check Regular expression. As scope you have to select Workspace
If you "pin" a search and open a new search window, the results from both searches will be highlighted throughout.