Find files with multiple Strings



  • ``

    I want to find all the files which has both the strings in any order.

    string are; abc and def or def and abc.

    The result should return only the files which has both the string in a file.

    ‘’



  • @vijay-S

    Maybe try something like this:

    (?s)(abc).+?(def)|(?2).+?(?1)



  • @Alan-Kilborn said in Find files with multiple Strings:

    (?s)(abc).+?(def)|(?2).+?(?1)

    ``
    Works like a charm. Thank You…
    ‘’



  • Hello, @vijay-s @alan-kilborn and All,

    As @alan-kilborn, I’ve already used this method. However, it quickly becomes tedious if you increase the number of expressions :-((

    I think, that this other formulation is stronger and can be easily used, even if more than two expressions to match !

    • (?-is)^(?=.*Expr_1)(?=.*Expr_2)(?=.*Expr_3)(?=.*Expr_n).+ ( sensitive to case )

    • (?i-s)^(?=.*Expr_1)(?=.*Expr_2)(?=.*Expr_3)(?=.*Expr_n).+ ( insensitive to case )


    For instance, the regex (?i-s)^(?=.*abc)(?=.*def)(?=.*ghi)(?=.*jkl).+ will find all files which have, at least, one line containing the four strings abc, def , ghi and jkl, in any order and whatever their case !

    Best Regards

    guy038



  • All,

    See also my in-development expressions for generic logic “gates” in regular expressions: AND, OR, XOR, NOR, NAND

    Some day, they might get a blog post all of their own, rather than be buried in that thread. But they are still in-development, so they’ll stay there for now.


Log in to reply