Questions tagged [negate]

84 questions
469
votes
14 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.…
assylias
  • 321,522
  • 82
  • 660
  • 783
275
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…
David Rogers
  • 4,010
  • 3
  • 29
  • 28
237
votes
5 answers

Negate if condition in bash script

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 connected to the…
Sudh33ra
  • 2,675
  • 3
  • 15
  • 19
146
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…
secr
  • 2,743
  • 3
  • 20
  • 20
108
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;
Frank Vilea
  • 8,323
  • 20
  • 65
  • 86
65
votes
4 answers

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 ?
user2239318
  • 2,578
  • 7
  • 28
  • 50
56
votes
6 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…
Yuval A.
  • 5,849
  • 11
  • 51
  • 63
46
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…
mrl
  • 1,467
  • 2
  • 14
  • 22
27
votes
4 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…
Yippie-Ki-Yay
  • 22,026
  • 26
  • 90
  • 148
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…
Splynx
  • 823
  • 2
  • 8
  • 20
13
votes
2 answers

Convert positive value to negative value in swift

I want to convert a positive value to a negative value, for example: let a: Int = 10 turn it to -10, my current idea is just use it to multiple -1 a * -1 I'm not sure if this is proper, any idea?
William Hu
  • 15,423
  • 11
  • 100
  • 121
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)?
anchandra
  • 1,089
  • 12
  • 23
10
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.
nickthedude
  • 4,925
  • 10
  • 36
  • 51
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…
Vigrond
  • 8,148
  • 4
  • 28
  • 46
8
votes
2 answers

select columns that do NOT start with a string using dplyr in R

I want to select columns from my tibble that end with the letter R AND do NOT start with a character string ("hc"). For instance, if I have a dataframe that looks like this: name hc_1 hc_2 hc_3r hc_4r lw_1r lw_2 lw_3r lw_4 Joe 1 2 …
J.Sabree
  • 2,280
  • 19
  • 48
1
2 3 4 5 6