Questions tagged [inverse-match]

Use this tag for questions where the desired goal is to match a pattern, for the purpose of excluding it from the end result.

Inverse matching is used to select a pattern from within text, and then "match" everything except for the pattern. Situations where this might be prudent often arise when it's easier to match bad content than it is to match the desired content.

  • Regular expressions are often implicated with this tag; the behavior can be emulated (to an extent) with a tempered greedy token.

  • In SQL, a FULL OUTER JOIN without intersection will "inverse match" an INNER JOIN, selecting data from the left and right tables if and only if the data does not have a match in the other table.

  • In set theory, the union of A and B minus the intersection of A and B (a | b) - (a & b) leaves behind the opposite of the intersection - a set where the data is present in only A or B, not both.

11 questions
160
votes
10 answers

How can I "inverse match" with regex?

I'm processing a file, line-by-line, and I'd like to do an inverse match. For instance, I want to match lines where there is a string of six letters, but only if these six letters are not 'Andrea'. How should I do that? I'm using RegexBuddy, but…
Andrea Ambu
  • 38,188
  • 14
  • 54
  • 77
3
votes
1 answer

How to force rematch?

I would like to force rematch in the following scenario - I'm trying to inverse match a qualifier after each element in a list. In other words I have: "int a, b, c" =~ m{ (?(DEFINE) (?\s*(?\bint\b|\bfloat\b)\s*+(?{print…
AnArrayOfFunctions
  • 3,452
  • 2
  • 29
  • 66
2
votes
1 answer

How do I restrict a string to a specific set of characters in JavaScript?

To put this in context, consider these 2 functions: ml_RestrictToChars = function(input,regex) { var result = '';var c = ''; var rx = new RegExp(regex); for (var i = 0; i < input.length; i++) { c = input.charAt(i); if…
NightOwl888
  • 55,572
  • 24
  • 139
  • 212
2
votes
6 answers

Latex Inverse search from a pdf in Okular to TexMaker

I am using TexMaker of Karmic Ubuntu with Okular. I use pdfLatex to compile and I view the PDFs in Okular. How can I configure Okular to inverse search with TexMaker? I have tried the following code: texmaker %f -line %l but it does not work. I have…
KBP
  • 1,500
  • 2
  • 14
  • 14
2
votes
1 answer

Regular expression to match string ending with letter but NOT ending with a phrase in R

I need to use grep to find all strings ending with G but NOT ending with STIG or VÄG in the following character vector: test=c("EWASPG","AVOPW","SDAGSTIG","ASDVVÄG","ASDVWE","QSCIUVG","QWSFNJG") I tried this but it returns false for any string with…
RobustTurd
  • 93
  • 8
1
vote
1 answer

bash 4.1.2(2): how to apply regex inverse matching in a for-loop?

I want to loop through only the directories that do NOT contain string "unicredit". Given this directory list (located in /tmp/scripts/bash/test/): par_q swx_i swx_r unicreditucispa_ams_b unicreditucispa_ams_m unicreditucispa_ber_b I launched the…
kamokoba
  • 497
  • 9
  • 17
0
votes
2 answers

Regex invert selection

I looked around quit a bit but was unable to find an answer to this question. I'm trying to select everything from a string except white spaces that repeat over a certain number of times. I've found a regex to select the white spaces, and what I was…
SuperStew
  • 2,857
  • 2
  • 15
  • 27
0
votes
4 answers

Inverse Match Help in Python

Hello I am looking to trim a McAfee log file and remove all of the "is OK" and other reported instances that I am not interested in seeing. Before we used a shell script that took advantage of the -v option for grep, but now we are looking to write…
el_loza
  • 47
  • 2
  • 8
0
votes
2 answers

Inverse Match with Python

I've been trying to work with two lists in Python 2.7. I've come part way, but spending some time searching hasn't brought up much in the way of results. List1: Is a list of specific numbers sequences that I was searching within List2. (e.g.)…
sdavis891
  • 101
  • 1
  • 3
  • 10
-1
votes
1 answer

Grep -v -f filename not working on one server

I've been running a script to extract Exchange mail recipient addresses and update my local postfix relay_recipients table for years. Script comes from The Book of Postfix, has worked flawlessly until now. The key line that is causing issues still…
-1
votes
1 answer

Summing column values for (and only for) deleted reversed duplicates with their undeleted reversed originals with R

I have a dataset containing instances of crime, each of which have a location (wardId), crime type (Primary.Type) and Date. The eventual goal is to turn this into network with Primary.Type's as nodes, and the weights of their edges to depend on the…