Questions tagged [negate]
81 questions
377
votes
12 answers
How to negate a method reference predicate
In Java 8, you can use a method reference to filter a stream, for example:
Stream s = ...;
long emptyStrings = s.filter(String::isEmpty).count();
Is there a way to create a method reference that is the negation of an existing one, i.e.…
![](../../users/profiles/829571.webp)
assylias
- 297,541
- 71
- 621
- 741
212
votes
5 answers
How do I negate a test with regular expressions in a bash script?
Using GNU bash (version 4.0.35(1)-release (x86_64-suse-linux-gnu), I would like to negate a test with Regular Expressions. For example, I would like to conditionally add a path to the PATH variable, if the path is not already there, as…
![](../../users/profiles/214961.webp)
David Rogers
- 3,210
- 3
- 24
- 27
198
votes
5 answers
Negate if condition in bash script
I'm new to bash and I'm stuck at trying to negate the following command:
wget -q --tries=10 --timeout=20 --spider http://google.com
if [[ $? -eq 0 ]]; then
echo "Sorry you are Offline"
exit 1
This if condition returns true if I'm…
![](../../users/profiles/3387528.webp)
Sudh33ra
- 2,237
- 3
- 11
- 16
109
votes
7 answers
How can I negate the return-value of a process?
I'm looking for a simple, but cross-platform negate-process that negates the value a process returns. It should map 0 to some value != 0 and any value != 0 to 0, i.e. the following command should return "yes, nonexistingpath doesn't exist":
ls…
![](../../users/profiles/4085.webp)
secr
- 2,293
- 3
- 18
- 18
100
votes
10 answers
SQL WHERE condition is not equal to?
Is it possible to negate a where clause?
e.g.
DELETE * FROM table WHERE id != 2;
![](../../users/profiles/698641.webp)
Frank Vilea
- 7,763
- 20
- 61
- 85
51
votes
3 answers
python how to "negate" value : if true return false, if false return true
if myval == 0:
nyval=1
if myval == 1:
nyval=0
Is there a better way to do a toggle in python, like a nyvalue = not myval ?
![](../../users/profiles/2239318.webp)
user2239318
- 1,891
- 5
- 20
- 39
50
votes
5 answers
Negating a backreference in Regular Expressions
if a string has this predicted format:
value = "hello and good morning"
Where the " (quotations) might also be ' (single quote), and the closing char (' or ") will be the same as the opening one. I want to match the string between the quotation…
![](../../users/profiles/522169.webp)
Yuval A.
- 5,007
- 9
- 47
- 59
32
votes
3 answers
Negative form of isinstance() in Python
How would I use a negative form of Python's isinstance()?
Normally negation would work something like
x != 1
if x not in y
if not a
I just haven't seen an example with isinstance(), so I'd like to know if there's a correct way to used negation…
![](../../users/profiles/1385836.webp)
mrl
- 1,028
- 2
- 10
- 20
25
votes
3 answers
C# negate an expression
I'm seeking for a way to negate an expression used to filter IQueryable sequences.
So, I've got something like:
Expression> expression = (x => true);
Now I wish to create the expression which would result in yielding (x => false) - so…
![](../../users/profiles/346332.webp)
Yippie-Ki-Yay
- 20,062
- 23
- 85
- 143
14
votes
3 answers
Javascript regexp - only if first character is not an asterisk
I am using a javascript validator which will let me build custom validation based on regexp
From their website: regexp=^[A-Za-z]{1,20}$ allow up to 20 alphabetic characters.
This will return an error if the entered data in the input field is outside…
![](../../users/profiles/427311.webp)
Splynx
- 683
- 1
- 7
- 20
10
votes
4 answers
.NET decimal.Negate vs multiplying by -1
Are there any differences between decimal.Negate(myDecimal) and myDecimal * -1 (except maybe readability)?
![](../../users/profiles/166521.webp)
anchandra
- 1,079
- 10
- 21
9
votes
2 answers
Negation of Hex in PHP, funny behavior
Got some weird behavior I was wondering if someone could clear up for me.
Check it out
$hex = 0x80008000;
print_r(decbin(intval($hex)) . '
'); print_r(decbin($hex)); Outputs 10000000000000001000000000000000 10000000000000001000000000000000 As…
'); print_r(decbin($hex)); Outputs 10000000000000001000000000000000 10000000000000001000000000000000 As…
![](../../users/profiles/728091.webp)
Vigrond
- 7,820
- 4
- 24
- 43
9
votes
8 answers
isn't there an operator in c to change the sign of a int float etc from negative to positive or vice versa?
trying to find absolute value and i thought there was a simple way to just invert the sign with '~' or something.
![](../../users/profiles/241068.webp)
nickthedude
- 4,835
- 8
- 33
- 50
8
votes
2 answers
Is there a reason why there is not std::identity in the standard library?
When dealing with generic code in C++, I would find a std::identity functor (like std::negate) very useful. Is there a particular reason why this is not present in the standard library?
![](../../users/profiles/882932.webp)
Vincent
- 50,257
- 51
- 171
- 339
7
votes
3 answers
How to Negate a Context
I want to select elements, but not if one of their ancestor matches a certain selector.
For example, let's say I want to match all nodes that are not descendants of a table.
I tried something like this:
$("a", ":not(table *)");
but that crashes…
![](../../users/profiles/299180.webp)
Aaron
- 2,702
- 2
- 27
- 43