Find in Files two phrases



  • I have a Year month directory structure and need to use “find all files”
    I’m looking to find all files that contain the phrases “Material Transfer Number” and “Posting Date”
    The results must contain both phrases.



  • @Scott-Wallace

    You can do a regular expression search of this type:

    (?-s)(?=.*phrase1)(?=.*phrase2).*



  • (?-s)(?=.*Material Transfer Number)(?=.Posting Date). in a folder where I know there are over 700 results I got back 15 hits that didn’t contain either phrase ??



  • @Scott-Wallace

    Ah, sorry, I thought for some reason that the phrases need to occur on the same line.

    Change the (?-s) part to (?s) – will allow matching to span lines.

    Note that this only helps you find which files contain the data, not the specific area in the file where the data is located.



  • @Scott-Wallace

    If you actually want the data matches to be shown, you could do this:

    (?s)phrase1.*?phrase2

    but you’d also have to do a second search to cover the possibility of phrase2 occurring before phrase1:

    (?s)phrase2.*?phrase1



  • @Alan-Kilborn
    First thank you for your help.
    So if I do just a plain Find in files search for “Material Transfer Number” I will get 765 hits.
    When the phrase appears in a file it would only appear a single time.
    When I search for Posting Date I get 1200 hits as that phrase in used in multiple XML files
    When I use (?s)(?=.*Material Transfer Number)(?=.Posting Date) it is extremely extremely slow and I get 785 hits
    Again Posting Date would only appear a single time in a file that has Material Transfer Numbers in it as well,so something is off with my results.

    Here is a more complete explanation. I have a folder structure of XMLs. I’m only interested in the XML files that contain the phrase Material Transfer Number. Within those files what I’m interested in is the value set for posting date.
    My attempt was to use a Find in Files for files that contain both phrases and for the results section to display the Posting Date line. Below is a sample
    <import>
    <node type=“document” action=“sync”>
    <location>Enteprise:Finance:Accounting:Material Transfers</location>
    <file>\Alpha1\oi-working$\filedrop\MTs\0000026.pdf</file>
    <title>0000026.pdf</title>
    <createby>svc.grooper</createby>
    <category name=“Content Server Categories:Material Transfer Packages”>
    <attribute name=“Material Transfer Number”>0000026</attribute>
    <attribute name=“Posting Date”>20191201</attribute>

    <attribute name=“Status”>Business Reference Not Created</attribute>
    <attribute name=“Material Number”>400020</attribute>
    <attribute name=“Equipment Number”>000000000010112769</attribute>
    </category>
    </node>
    </import>

    The order of the two phrases is always the same, but of course the value assigned always changes
    I’ve since tried your other suggestion
    (?s)Material Transfer Number.*?Posting Date
    But the above showed zero results.



  • @Scott-Wallace said in Find in Files two phrases:

    But the above showed zero results.

    Hmm, not sure.
    Here’s the result of my try at it:
    d2b3e743-1d34-491a-b1be-41a476836f0f-image.png
    Double-clicking the Line 8 result in the Find result window jumps the input focus into the main window to select all text beginning with Material and ending with Date.

    …results section to display the Posting Date line

    Ah, well for that you’d need to do it a bit differently as in my screenshot above Posting Date is not visible directly in the results, only when you double-click on a specific line in the results.
    The reason for this is that in the results, only the first line of a multiline result is shown.

    For that I would try this variation (?s)Material Transfer Number.*?\KPosting Date to obtain this where it IS visible in the results:

    32b596ce-6f52-4442-b962-85d7aaed5446-image.png

    The \K makes the posting date be the line that is shown in the results.

    When I use (?s)(?=.*Material Transfer Number)(?=.Posting Date) it is extremely extremely slow and I get 785 hits

    Again Posting Date would only appear a single time in a file that has Material Transfer Numbers in it as well,so something is off with my results.

    Hmm, not sure what is going wrong for you. “Extremely slow…” -> could be, depending upon size of the files.



  • @Alan-Kilborn said in Find in Files two phrases:

    (?s)Material Transfer Number.*?\KPosting Date

    Alan, the issues were typos on my side. The (?s)Material Transfer Number.*?\KPosting Date gave me exactly what I needed.
    Thank you so much for all your help.


Log in to reply