-1

I'm trying to create a test that examines each line and passes if anything but one of three options is present in the line. I do not want to pass if a line contains any one of the following:

foo bar donut

So if the data shows:

stuff foo more stuff
junk bar other junk
some other garbage

It would pass because of some other garbage

If it contains:

stuff foo more stuff
junk bar other junk
more stuff here for foo and stuff

It would not pass.

This also would not pass:

junk donut junk
stuff donut stuff
yar donut me matey

But this would pass:

statement completely void of key words

I hope this makes sense. And I appreciate your help!

I've tried this: ^(?!.*foo:), but it seems to only test the first line. I know this is only for foo, but I was going to work on multiple options once I got it working.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Do you mean `^(?!.*foo)(?!.*bar)(?!.*donut)`? – Wiktor Stribiżew Aug 15 '23 at 16:20
  • 1
    Hi Joseph! Welcome to StackOverflow! What tool/language are you using? – Mark Aug 15 '23 at 16:22
  • Sorry, I can't make sense of your requirements. Can you explain why exactly `stuff foo more stuff junk bar other junk more stuff here for foo and stuff` would not pass? – Grobu Aug 15 '23 at 16:36
  • 1
    You're not describing the requirement clearly and consistently. I think what you mean is "passes if it doesn't contain any of the three words". That's not the same as "contains something other than the three words". – Barmar Aug 15 '23 at 16:50
  • Your question also wasn't clear because you allowed your multi-line inputs to be wrapped into a single line. – Barmar Aug 15 '23 at 16:52
  • 1
    What language are you using? If you want to pass or fail the entire input based on individual lines, you'll need a language with looping. – Barmar Aug 15 '23 at 16:53
  • `and passes if anything but one of three options is present in the line` not in the **line** but in the source file, presumably? That is, if you can find a line that does not contain any of the forbidden patterns, the source file should be validated? Is that right? – Grobu Aug 15 '23 at 17:25
  • 1
    You can match the lines that do not contain any of the words by [`(?m)^(?!.*?\b(?:foo|bar|donut)\b)`](https://regex101.com/r/3YBQaL/1). If `^` matches a linestart depends on the environment. The `(?m)` flag if supported switches to *multiline* mode and makes the caret match *start of the line*. – bobble bubble Aug 15 '23 at 17:25
  • @WiktorStribiżew, that's what I was looking for. Thank you! – Joseph Odell Aug 15 '23 at 18:15

1 Answers1

0
^(?!.*foo)(?!.*bar)(?!.*donut)

This seems to do the trick!