tags:

views:

105

answers:

4
+3  Q: 

Regex AND'ing

I have to two strings that I want to match everything that doesn't equal them, the first string can be followed by a number of characters. I tried something like this, negating two ors and negating that result.

?!(?!^.*[^Factory]$|?![^AppName])

Any ideas?

A: 

Would it work if you looked for the existence of those two strings and then negated the regex?

Matt Bridges
+3  A: 

what about

if (!match("(Factory|AppName)")) {
    // your code
}
dfa
+2  A: 

dfa's answer is by far the best option. But if you can't use it for some reason, try:

^(?!.*Factory|AppName)

It's very difficult to determine from your question and your regex what you're trying to do; they seem to imply opposite behaviors. The regex I wrote will not match if Factory appears anywhere in the string, or AppName appears at the beginning of it.

chaos
+4  A: 

Try this regular expression:

(?!.*Factory$|.*AppName)^.*

This matches every string that does not end with Factory and does not contain AppName.

Gumbo