I'm using IntelliJ as my editor, it has Regex search function, but I couldn't do the following : If I'm searching in a project with lots of directories for a file containing 2 phrases [ "special property" and "spin waves"], how should I write the regex ?
Here is a sample file containing these 2 phrases :
The basic idea of spintronics is to use a special property of electrons—spin—for various electronic applications such as data and information technology. The spin is the intrinsic angular momentum of electrons that produces a magnetic moment. Coupling these magnetic moments creates the magnetism that could ultimately be used in information processing. When these coupled magnetic moments are locally excited by a magnetic field pulse, this dynamic can spread like waves throughout the material. These are referred to as spin waves or magnons.
I tried : special property.*spin waves
But it didn't work.
I have an idea but I don't know how to put it in Regex, is there a way to achieve the following :
[1] I've noticed if I do a search of "special property" or "spin waves", the results are instant, but I got too many files.
[2] Even if I do a search for "special property|spin waves", it's also instant, results will have either "special property" or "spin waves".
[3] So my idea is : if the the result files are in a set X for searching "special property", and the result files are in a set Y for searching "spin waves", can I come up with a Regex that return the files that are in both X and Y ?
CodePudding user response:
Search for the regular expression
(?s)(?=.*special property)spin waves
$(?s)
sets the dotall
flag, which allows .*
to match across newlines. Then it uses a lookahead to find one of the phrases while searching for the other one normally.
CodePudding user response:
Another option would be to first search for all files containing "special property" and then searching in the scope Files in previous search result
for "spin waves".