Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Regular expressions - "negating" a matching string

Options
  • 25-06-2007 4:25pm
    #1
    Registered Users Posts: 1,127 ✭✭✭


    I want to search and return files from a filesystem, that DONT contain a particular string. I need a little help.

    My regex sucks, but I assumed that it would be something like !^foo or something like that?

    am I way off?


Comments

  • Moderators, Science, Health & Environment Moderators Posts: 10,079 Mod ✭✭✭✭marco_polo


    I want to search and return files from a filesystem, that DONT contain a particular string. I need a little help.

    My regex sucks, but I assumed that it would be something like !^foo or something like that?

    am I way off?

    I think [^foo] would work to exclude this string. To the best of my limited knowledge on this subject the square brackets are important. I think ^foo without the brackets would match "foo" only if it occurs at the beginning of a line.


  • Subscribers Posts: 4,076 ✭✭✭IRLConor


    grep -Lr foo dir
    

    will recursively search the directory dir and print the names of the files which do not match the regex foo.

    What tool/language are you using?

    [^foo] will not do it, that matches a single character which is anything except 'f' or 'o'.


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes




  • Closed Accounts Posts: 97 ✭✭koloughlin




Advertisement