Regular Expression Negation

I can use "Alternation" in the regex to match any "cat" or "dog" situation:

(cat|dog)

Is it possible for NEGATE to interleave and match anything that is not "cat" or "dog"?

If so, how?

Example:

Let's say I'm trying to get closer to END OF SENTENCE in English like this.

To Wit:

(\.)(\s+[A-Z][^.]|\s*?$)

In the following paragraph:

A quick brown fox jumps over a lazy dog. Once upon a time, Dr. Sanchez, Mr. Parsons, and Governor Mason went to the store. Hello World

I incorrectly find the "end of the sentence" from the doctor, Mr. and Governor.

(I am testing using http://regexpal.com/ if you want to see what I see with the above example)

, - :

!(Dr\.|Mr\.|Gov\.)(\.)(\s+[A-Z][^.]|\s*?$)

, , .

! /(Dr. | Mr. | Gov.)/, ! ~, .

"", "-", "Gov." ..?

.

+3
4

. lookbehind (?<!…), JavaScript regex flavor . , , .

+2

Perl/awk !~

$string !~ /(cat|dog)/

ActionScript NOT !, . . . regex

0

:

!/(cat|dog)/

EDIT: . ActionScript ? ActionScript, AFAIK :

var pattern2:RegExp = !/(cat|dog)/;
0

(?! NotThisStuff) - , , .

, , . /(?! Dr \.) (\.)/ , "Dr. Sanches" - . Regex : ", ". "" "/((! Dr).)/ , , .

, "". ActionScript "match all", . ( g ) exec , result .

var string = 'The quick brown fox jumps over the lazy dog. Once upon a time Dr. Sanches, Mr. Parsons and Gov. Mason went to the store. Hello World.';

var regx:RegExp = /(?!Dr\.)(\.)/g;
var result:Object = regx.exec(string);

for (var i = 0; i < 10; i++) { // paranoia
  if (result == null || result.index == 0) break; // again: paranoia
  trace(result.index, result);
  result = regx.exec(string);
}

// trace results:    
//43 .,.
//64 .,.
//77 .,.
//94 .,.
//119 .,.
//132 .,.
0

Source: https://habr.com/ru/post/1770224/


All Articles