Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Regular expressions - "negating" a matching string

  • 25-06-2007 03:25PM
    #1
    Registered Users, Registered Users 2 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,093 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,077 ✭✭✭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, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes




  • Closed Accounts Posts: 97 ✭✭koloughlin




Advertisement