Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Regular expressions - "negating" a matching string

  • 25-06-2007 04: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